Fix wrong api key error handling

This commit is contained in:
Iam54r1n4
2025-02-07 17:38:05 +00:00
parent da421b0d15
commit 9dcace9792
3 changed files with 22 additions and 12 deletions

View File

@ -1 +1 @@
from .handler import setup_exception_handler
from .handler import setup_exception_handler, exception_handler

View File

@ -13,8 +13,12 @@ def setup_exception_handler(app: FastAPI):
Setup exception handler for FastAPI.
'''
@app.exception_handler(HTTPException)
async def http_exception_handler(request: Request, exc: HTTPException): # type: ignore
return JSONResponse(
status_code=exc.status_code,
content=JSONErrorResponse(status=exc.status_code, detail=exc.detail).model_dump(),
)
async def http_exception_handler_wrapper(request: Request, exc: HTTPException): # type: ignore
return exception_handler(exc)
def exception_handler(exc: HTTPException): # type: ignore
return JSONResponse(
status_code=exc.status_code,
content=JSONErrorResponse(status=exc.status_code, detail=exc.detail).model_dump(),
)