refactor: cleaned main file
This commit is contained in:
17
core/exceptions.py
Normal file
17
core/exceptions.py
Normal file
@ -0,0 +1,17 @@
|
||||
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})
|
||||
Reference in New Issue
Block a user