Skip to content

Commit

Permalink
Uniform the use of 400 error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
avvertix committed Sep 10, 2024
1 parent d84570f commit f611871
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
logs
.env
.env
__pycache__
4 changes: 2 additions & 2 deletions text_extractor_api/routers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def parse_pdf(request: ExtractTextRequest) -> Document:
f.write(resp.content)
except HTTPError as http_err:
logger.exception("Error while downloading file.", exc_info=True)
raise HTTPException(status_code=500, detail=f"Error while downloading file [{http_err}]")
raise HTTPException(status_code=400, detail=f"Error while downloading file [{http_err}]")
except Timeout as http_timeout:
logger.exception("Timeout while downloading file.", exc_info=True)
raise HTTPException(status_code=408, detail=f"File download not completed [{http_timeout}]")
Expand All @@ -72,7 +72,7 @@ async def parse_pdf(request: ExtractTextRequest) -> Document:
raise HTTPException(status_code=503, detail="The pdfact service is not reachable")
except Exception as err:
logger.exception(f"Error while parsing file. {str(err)}", exc_info=True)
raise HTTPException(status_code=502, detail="Error while parsing file")
raise HTTPException(status_code=400, detail="Error while parsing file")
finally:
if os.path.exists(file_path):
os.remove(file_path)
Expand Down

0 comments on commit f611871

Please sign in to comment.