Eng-Musa commited on
Commit
70da0b3
·
1 Parent(s): d581f2c

return all responses in the api response wrapper

Browse files
__pycache__/main.cpython-312.pyc CHANGED
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
 
main.py CHANGED
@@ -41,9 +41,38 @@ class APIResponse(BaseModel):
41
  # Validation error handler
42
  # ---------------------------------------------------------------------------
43
 
 
 
 
44
  @app.exception_handler(RequestValidationError)
45
  async def validation_exception_handler(request, exc):
46
- return APIResponse(message="Invalid request: " + str(exc.errors()[0].get("msg", exc)), statusCode=400)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
 
49
  # ---------------------------------------------------------------------------
 
41
  # Validation error handler
42
  # ---------------------------------------------------------------------------
43
 
44
+ from fastapi.responses import JSONResponse
45
+ from starlette.exceptions import HTTPException as StarletteHTTPException
46
+
47
  @app.exception_handler(RequestValidationError)
48
  async def validation_exception_handler(request, exc):
49
+ return JSONResponse(
50
+ status_code=400,
51
+ content=APIResponse(
52
+ message="Invalid request: " + str(exc.errors()),
53
+ statusCode=400
54
+ ).model_dump()
55
+ )
56
+
57
+ @app.exception_handler(StarletteHTTPException)
58
+ async def http_exception_handler(request, exc):
59
+ return JSONResponse(
60
+ status_code=exc.status_code,
61
+ content=APIResponse(
62
+ message=str(exc.detail),
63
+ statusCode=exc.status_code
64
+ ).model_dump()
65
+ )
66
+
67
+ @app.exception_handler(Exception)
68
+ async def global_exception_handler(request, exc):
69
+ return JSONResponse(
70
+ status_code=500,
71
+ content=APIResponse(
72
+ message="Internal server error: " + str(exc),
73
+ statusCode=500
74
+ ).model_dump()
75
+ )
76
 
77
 
78
  # ---------------------------------------------------------------------------
services/__pycache__/cv_chunker.cpython-312.pyc CHANGED
Binary files a/services/__pycache__/cv_chunker.cpython-312.pyc and b/services/__pycache__/cv_chunker.cpython-312.pyc differ