Skip to content

Un-reachable exceptions #4

@RafaPolit

Description

@RafaPolit

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions