refactor: entity not found exceptions handler
This commit is contained in:
10
main.py
10
main.py
@ -1,12 +1,14 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.middleware.gzip import GZipMiddleware
|
||||
from fastapi.responses import ORJSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
import modules
|
||||
import routers
|
||||
from utils.auto_include_routers import auto_include_routers
|
||||
from utils.exceptions import ObjectNotFoundException
|
||||
|
||||
origins = ["http://localhost:3000"]
|
||||
|
||||
@ -28,6 +30,12 @@ app.add_middleware(
|
||||
minimum_size=1_000,
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(ObjectNotFoundException)
|
||||
async def unicorn_exception_handler(request: Request, exc: ObjectNotFoundException):
|
||||
return JSONResponse(status_code=404, content={"detail": exc.name})
|
||||
|
||||
|
||||
auto_include_routers(app, routers)
|
||||
auto_include_routers(app, modules, True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user