diff --git a/server/app.py b/server/app.py index 4853b24..bf39010 100644 --- a/server/app.py +++ b/server/app.py @@ -2,6 +2,7 @@ import os from fastapi import Depends, FastAPI, Header, HTTPException, Query +from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse from . import actions, jobs, mf @@ -23,6 +24,11 @@ async def _http_exc(_req, exc: HTTPException): return JSONResponse(status_code=exc.status_code, content={"message": exc.detail}) +@app.exception_handler(RequestValidationError) +async def _validation_exc(_req, exc: RequestValidationError): + return JSONResponse(status_code=422, content={"message": "Invalid or missing request parameters."}) + + @app.get("/health") def health(): return {"status": "ok"} diff --git a/tests/test_api.py b/tests/test_api.py index 0df91c4..8c63d15 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -45,6 +45,7 @@ def test_fetch_no_hits_returns_404(client, auth, monkeypatch): def test_fetch_missing_q_returns_422(client, auth): r = client.post("/fetch", headers=auth) assert r.status_code == 422 + assert "message" in r.json() def test_job_lifecycle_done(client, auth, monkeypatch):