feat: add proper HTTP status codes to all API error responses
- 217 error returns across 18 route files + api.py now use JSONResponse with appropriate HTTP status codes instead of returning HTTP 200 - Status code distribution: 500 (121), 400 (39), 503 (28), 404 (24), 409 (3), 502 (2) - Fixed language.py tuple-return bug (was serializing as JSON array) - Fixed bare except clauses in bipolar_mode.py and voice.py - Body-level error schemas preserved (status/error + success/error patterns) so web UI continues working without changes - chat.py (SSE) unchanged: errors sent within stream protocol - All 170 tests pass
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
# To revert: cp api_monolith_backup.py api.py
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from utils.logger import get_logger
|
||||
from utils.log_config import load_config as load_log_config
|
||||
@@ -23,7 +24,7 @@ app = FastAPI()
|
||||
async def global_exception_handler(request: Request, exc: Exception):
|
||||
"""Catch all unhandled exceptions and log them properly."""
|
||||
logger.error(f"Unhandled exception on {request.method} {request.url.path}: {exc}", exc_info=True)
|
||||
return {"success": False, "error": "Internal server error"}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": "Internal server error"})
|
||||
|
||||
# ========== Logging Middleware ==========
|
||||
@app.middleware("http")
|
||||
|
||||
Reference in New Issue
Block a user