-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (23 loc) · 1.02 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from fastapi import FastAPI
from starlette.middleware import Middleware
from middleware.time import TimerMiddleware
from routes import users, auth, property
middleware = [Middleware(TimerMiddleware)]
app = FastAPI(middleware=middleware)
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from pydantic import ValidationError
@app.exception_handler(ValidationError)
async def validation_exception_handler(_, exc: ValidationError):
err = exc.errors().pop()
err["input"] = str(err["input"]) # dict "serialization"
return JSONResponse(err, status_code=400)
@app.exception_handler(RequestValidationError)
async def request_validation_exception_handler(_, exc: RequestValidationError):
err = exc.errors()[0]
err["input"] = str(err["input"]) # dict "serialization"
return JSONResponse(err, status_code=400)
# app.add_middleware()
app.include_router(auth.router)
app.include_router(users.router, prefix="/users")
app.include_router(property.router, prefix="/property")