Skip to content

Commit

Permalink
add APIResponseExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
taogeYT committed Dec 25, 2024
1 parent f205aba commit 47f1713
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions appboot/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from appboot.conf import settings
from appboot.db import transaction
from appboot.exceptions import Error
from appboot.response import APIResponse


class ExceptionHandler:
Expand All @@ -27,6 +28,12 @@ async def handle_exception(cls, request: Request, exc: Exception):
return await cls(request, exc).make_response()


class APIResponseExceptionHandler(ExceptionHandler):
async def make_response(self):
data = APIResponse.from_exception(self.exc)
return JSONResponse(data.dict(exclude_unset=True), status_code=data.code)


def get_asgi_application():
return get_fastapi_application()

Expand Down

0 comments on commit 47f1713

Please sign in to comment.