Skip to content

Commit

Permalink
Mapping even more HTTP exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneTR committed Sep 19, 2023
1 parent 364aef0 commit 37a56fb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from fastapi.middleware.cors import CORSMiddleware

from starlette.responses import RedirectResponse
from starlette.exceptions import HTTPException as StarletteHTTPException

from pydantic import BaseModel

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../lib')
Expand Down Expand Up @@ -71,6 +73,14 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
content=jsonable_encoder({"detail": exc.errors(), "body": exc.body}),
)

@app.exception_handler(StarletteHTTPException)
async def http_exception_handler(request, exc):
await log_exception(request, exc.detail, exc)
return ORJSONResponse(
status_code=exc.status_code,
content=jsonable_encoder({"detail": exc.detail}),
)

async def catch_exceptions_middleware(request: Request, call_next):
#pylint: disable=broad-except
try:
Expand Down

0 comments on commit 37a56fb

Please sign in to comment.