Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Un-reachable exceptions #4

Open
RafaPolit opened this issue Oct 18, 2022 · 0 comments
Open

Un-reachable exceptions #4

RafaPolit opened this issue Oct 18, 2022 · 0 comments

Comments

@RafaPolit
Copy link
Member

pdf_ocr_service/src/app.py

Lines 97 to 107 in 8d2f336

try:
return FileResponse(
path=f'{config.paths["processed_pdfs"]}/{namespace}/{pdf_file_name}',
media_type="application/pdf",
filename=pdf_file_name,
)
except FileNotFoundError:
raise HTTPException(status_code=404, detail="No processed file found")
except Exception:
logger.error("Error", exc_info=1)
raise HTTPException(status_code=422)

These exceptions are not reachable, due to the fact that the exception from FileResponse is raised after the return.

As noted in https://stackoverflow.com/questions/74103330/fastapi-fileresponse-not-entering-the-except-block/74103398#74103398 a simple os.stat() on the file's path before the return is enough to trigger the exceptions as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant