diff options
| author | 2024-08-16 17:53:52 +0100 | |
|---|---|---|
| committer | 2024-08-16 17:53:52 +0100 | |
| commit | 71d1ea51a4e9ccafd56bdcb5dba126f2b1831a36 (patch) | |
| tree | 354c4d5c077036b22db6d1a8717fdb1540807929 /thallium-backend/src/app.py | |
| parent | Add a basic litestar app (diff) | |
Move to fastapi & mono repo layout
Diffstat (limited to 'thallium-backend/src/app.py')
| -rw-r--r-- | thallium-backend/src/app.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/thallium-backend/src/app.py b/thallium-backend/src/app.py new file mode 100644 index 0000000..27ec8ab --- /dev/null +++ b/thallium-backend/src/app.py @@ -0,0 +1,25 @@ +import logging + +from fastapi import FastAPI, Request +from fastapi.exceptions import RequestValidationError +from fastapi.responses import JSONResponse + +from src.settings import CONFIG + +log = logging.getLogger(__name__) + + +fastapi_app = FastAPI(debug=CONFIG.debug) + + +@fastapi_app.get("/heartbeat") +def health_check() -> JSONResponse: + """Return basic response, for use as a health check.""" + return JSONResponse({"detail": "I am alive!"}) + + +@fastapi_app.exception_handler(RequestValidationError) +def pydantic_validation_error(request: Request, error: RequestValidationError) -> JSONResponse: + """Raise a warning for pydantic validation errors, before returning.""" + log.warning("Error from %s: %s", request.url, error) + return JSONResponse({"error": str(error)}, status_code=422) |