diff --git a/fastapi/exception_handlers.py b/fastapi/exception_handlers.py index 6c8db3d00aa45..1872cbf2613e5 100644 --- a/fastapi/exception_handlers.py +++ b/fastapi/exception_handlers.py @@ -10,7 +10,7 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> Response: headers = getattr(exc, "headers", None) if not is_body_allowed_for_status_code(exc.status_code): - return Response(status_code=exc.status_code, headers=exc.headers) + return Response(status_code=exc.status_code, headers=headers) if headers: return JSONResponse( {"detail": exc.detail}, status_code=exc.status_code, headers=headers