From f6118711b4c1e6c10ef8f4476443e45593efc045 Mon Sep 17 00:00:00 2001 From: Alessio Vertemati Date: Tue, 10 Sep 2024 14:48:21 +0200 Subject: [PATCH] Uniform the use of 400 error codes --- .gitignore | 3 ++- text_extractor_api/routers/parser.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5cf0957..b6c83e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea logs -.env \ No newline at end of file +.env +__pycache__ \ No newline at end of file diff --git a/text_extractor_api/routers/parser.py b/text_extractor_api/routers/parser.py index 9d1ea6c..018c3b1 100644 --- a/text_extractor_api/routers/parser.py +++ b/text_extractor_api/routers/parser.py @@ -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}]") @@ -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)