exc-mw
All checks were successful
Deploy on push / deploy (push) Successful in 1m8s

This commit is contained in:
2024-06-04 08:10:57 +03:00
parent 231de135ca
commit d53256bcd7
4 changed files with 23 additions and 12 deletions

17
services/exception.py Normal file
View File

@@ -0,0 +1,17 @@
import logging
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
logger = logging.getLogger("exception")
logging.basicConfig(level=logging.DEBUG)
class ExceptionHandlerMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
try:
response = await call_next(request)
return response
except Exception as exc:
logger.exception(exc)
return JSONResponse({"detail": "An error occurred. Please try again later."}, status_code=500)