-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
28 lines (22 loc) · 781 Bytes
/
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
from fastapi.exceptions import HTTPException
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from config.database_config import data_base_config
from tortoise.contrib.fastapi import register_tortoise
from routers import category_api, keyword_api
app = FastAPI(title="Expense tracker")
register_tortoise(
app,
modules={"models": ["_models_"]},
config=data_base_config,
generate_schemas=True,
add_exception_handlers=True,
)
app.include_router(category_api.router)
app.include_router(keyword_api.router)
@app.exception_handler(HTTPException)
async def unicorn_exception_handler(request: Request, exc: HTTPException):
return JSONResponse(
status_code=exc.status_code,
content={"message": exc.detail},
)