diff --git a/appboot/asgi.py b/appboot/asgi.py index 4c5bd3f..f80b104 100644 --- a/appboot/asgi.py +++ b/appboot/asgi.py @@ -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: @@ -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()