wip: crud refactor

This commit is contained in:
grillazz
2025-08-23 17:53:18 +02:00
parent 93f2e66bd0
commit d722504e55
6 changed files with 30 additions and 31 deletions

View File

@@ -3,9 +3,10 @@ from pathlib import Path
import asyncpg
from fastapi import Depends, FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.templating import Jinja2Templates
from rotoger import AppStructLogger
from sqlalchemy.exc import SQLAlchemyError
from app.api.health import router as health_router
from app.api.ml import router as ml_router
@@ -61,6 +62,19 @@ def create_app() -> FastAPI:
dependencies=[Depends(AuthBearer())],
)
@app.exception_handler(SQLAlchemyError)
async def sqlalchemy_exception_handler(request: Request, exc: SQLAlchemyError):
await logger.aerror(
"A database error occurred",
sql_error=repr(exc),
request_url=request.url.path,
request_body=request.body,
)
return JSONResponse(
status_code=500,
content={"message": "A database error occurred. Please try again later."},
)
@app.get("/index", response_class=HTMLResponse)
def get_index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})