Stage 9: add read-only FastAPI query API for juror RAG queries
8 GET endpoints under /api/v1 for health, personas, cases, vector search,
juror context, and hybrid search. Includes QueryService composing SubgraphQuery
+ VectorIndex + GraphDB, Pydantic response models, error handlers, and
`serve` CLI mode via uvicorn. 20 new tests, 190 total, zero regressions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-30 02:08:55 +00:00
|
|
|
"""Error handlers for the query API."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-05-30 02:17:55 +00:00
|
|
|
import logging
|
|
|
|
|
|
Stage 9: add read-only FastAPI query API for juror RAG queries
8 GET endpoints under /api/v1 for health, personas, cases, vector search,
juror context, and hybrid search. Includes QueryService composing SubgraphQuery
+ VectorIndex + GraphDB, Pydantic response models, error handlers, and
`serve` CLI mode via uvicorn. 20 new tests, 190 total, zero regressions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-30 02:08:55 +00:00
|
|
|
from fastapi import FastAPI, Request
|
|
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
|
2026-05-30 02:17:55 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
Stage 9: add read-only FastAPI query API for juror RAG queries
8 GET endpoints under /api/v1 for health, personas, cases, vector search,
juror context, and hybrid search. Includes QueryService composing SubgraphQuery
+ VectorIndex + GraphDB, Pydantic response models, error handlers, and
`serve` CLI mode via uvicorn. 20 new tests, 190 total, zero regressions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-30 02:08:55 +00:00
|
|
|
|
|
|
|
|
def register_error_handlers(app: FastAPI) -> None:
|
|
|
|
|
@app.exception_handler(ValueError)
|
|
|
|
|
async def value_error_handler(request: Request, exc: ValueError):
|
|
|
|
|
return JSONResponse(status_code=400, content={"detail": str(exc)})
|
|
|
|
|
|
2026-05-30 02:17:55 +00:00
|
|
|
@app.exception_handler(Exception)
|
|
|
|
|
async def generic_error_handler(request: Request, exc: Exception):
|
|
|
|
|
logger.exception("Unhandled exception in query API")
|
|
|
|
|
return JSONResponse(status_code=500, content={"detail": "Internal server error"})
|