Skip to content

Commit

Permalink
♻️ Simplify exception handler implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Sep 11, 2022
1 parent d21ce64 commit 1fe25cf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions fastapi/exception_handlers.py
Expand Up @@ -11,12 +11,9 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> Respon
headers = getattr(exc, "headers", None)
if not is_body_allowed_for_status_code(exc.status_code):
return Response(status_code=exc.status_code, headers=headers)
if headers:
return JSONResponse(
{"detail": exc.detail}, status_code=exc.status_code, headers=headers
)
else:
return JSONResponse({"detail": exc.detail}, status_code=exc.status_code)
return JSONResponse(
{"detail": exc.detail}, status_code=exc.status_code, headers=headers
)


async def request_validation_exception_handler(
Expand Down

0 comments on commit 1fe25cf

Please sign in to comment.