Files
Crm-Backend/core/exceptions.py
2025-10-31 11:29:24 +04:00

18 lines
678 B
Python

from fastapi import Request
from fastapi.applications import AppType
from starlette.responses import JSONResponse
from utils.exceptions import ObjectNotFoundException, ForbiddenException
def register_exception_handlers(app: AppType):
@app.exception_handler(ObjectNotFoundException)
async def not_found_exception_handler(
request: Request, exc: ObjectNotFoundException
):
return JSONResponse(status_code=404, content={"detail": exc.name})
@app.exception_handler(ForbiddenException)
async def forbidden_exception_handler(request: Request, exc: ForbiddenException):
return JSONResponse(status_code=403, content={"detail": exc.name})