Skip to content

Commit 5bb40bb

Browse files
committed
refactor: use default FastAPI handler instead of custom ORJSONResponse
1 parent f97d556 commit 5bb40bb

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

tracecat/api/common.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from fastapi import HTTPException, Request, Response, status
2+
from fastapi.exception_handlers import http_exception_handler as default_http_handler
23
from fastapi.responses import ORJSONResponse
34
from fastapi.routing import APIRoute
45
from sqlalchemy import select
@@ -39,27 +40,20 @@ def generic_exception_handler(request: Request, exc: Exception) -> Response:
3940
)
4041

4142

42-
def http_exception_handler(request: Request, exc: Exception) -> Response:
43+
async def http_exception_handler(request: Request, exc: Exception) -> Response:
4344
"""Log HTTP exceptions with tenant context for observability."""
44-
if not isinstance(exc, HTTPException):
45-
return ORJSONResponse(
46-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
47-
content={"detail": str(exc)},
48-
)
45+
http_exc = exc if isinstance(exc, HTTPException) else HTTPException(500, str(exc))
4946
role = ctx_role.get()
50-
log_method = logger.warning if exc.status_code < 500 else logger.error
47+
log_method = logger.warning if http_exc.status_code < 500 else logger.error
5148
log_method(
5249
"HTTP error",
53-
status_code=exc.status_code,
54-
detail=exc.detail,
50+
status_code=http_exc.status_code,
51+
detail=http_exc.detail,
5552
path=request.url.path,
5653
method=request.method,
5754
role=role,
5855
)
59-
return ORJSONResponse(
60-
status_code=exc.status_code,
61-
content={"detail": exc.detail},
62-
)
56+
return await default_http_handler(request, http_exc)
6357

6458

6559
def bootstrap_role(organization_id: OrganizationID | None = None) -> Role:

0 commit comments

Comments
 (0)