Skip to content

Commit

Permalink
🐛 HTTPException -> JSONResponse: fix exception handler in api-server (I…
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis authored Feb 28, 2024
1 parent 194830a commit 524b781
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import logging
from typing import Any

from fastapi import HTTPException, Request, status
from fastapi import Request, status
from fastapi.responses import JSONResponse
from httpx import HTTPError, TimeoutException

_logger = logging.getLogger(__file__)
Expand All @@ -30,6 +31,6 @@ async def handle_httpx_client_exceptions(_: Request, exc: HTTPError):

if status_code >= status.HTTP_500_INTERNAL_SERVER_ERROR:
_logger.exception("%s. host=%s. %s", detail, exc.request.url.host, f"{exc}")
raise HTTPException(
status_code=status_code, detail=detail, headers=headers
) from exc
return JSONResponse(
status_code=status_code, content={"detail": detail}, headers=headers
)

0 comments on commit 524b781

Please sign in to comment.