feat: add custom exceptions
This commit is contained in:
15
src/presentation/handler/application_exception_handler.py
Normal file
15
src/presentation/handler/application_exception_handler.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from fastapi import Request
|
||||
from fastapi.responses import ORJSONResponse
|
||||
from src.application.domain.exceptions import ApplicationException
|
||||
|
||||
|
||||
async def application_exception_handler(_request: Request, exc: ApplicationException) -> ORJSONResponse:
|
||||
detail = exc.message
|
||||
if 500 <= exc.status_code:
|
||||
detail = 'Internal Server Error'
|
||||
|
||||
return ORJSONResponse(
|
||||
status_code=exc.status_code,
|
||||
content={'detail': detail},
|
||||
headers=dict(exc.headers) if exc.headers else None,
|
||||
)
|
||||
Reference in New Issue
Block a user