added vegetation

This commit is contained in:
2026-06-23 13:57:33 +03:00
parent 0c9fc22d22
commit c7435955c3
32 changed files with 336 additions and 15 deletions
+27 -1
View File
@@ -1,4 +1,7 @@
from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from app.config import get_settings
from app.routers import api_router
@@ -16,6 +19,29 @@ def create_app() -> FastAPI:
def health() -> dict[str, str]:
return {"status": "ok"}
@app.exception_handler(StarletteHTTPException)
def http_exception_handler(_request: Request, exc: StarletteHTTPException) -> JSONResponse:
detail = exc.detail
if not (isinstance(detail, dict) and "code" in detail and "detail" in detail):
detail = {"code": "HTTP_ERROR", "detail": detail}
return JSONResponse(status_code=exc.status_code, content={"detail": detail})
@app.exception_handler(RequestValidationError)
def validation_exception_handler(
_request: Request,
exc: RequestValidationError,
) -> JSONResponse:
return JSONResponse(
status_code=422,
content={
"detail": {
"code": "VALIDATION_ERROR",
"detail": "Request validation failed",
"errors": exc.errors(),
}
},
)
app.include_router(api_router, prefix=settings.api_v1_prefix)
return app