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:
@@ -1,6 +1,7 @@
|
||||
"""Language mode routes."""
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.responses import JSONResponse
|
||||
import globals
|
||||
from utils.logger import get_logger
|
||||
|
||||
@@ -53,7 +54,7 @@ def toggle_language_mode():
|
||||
def set_language_mode(language: str = "english"):
|
||||
"""Set language mode to either 'english' or 'japanese'"""
|
||||
if language.lower() not in ["english", "japanese"]:
|
||||
return {"error": f"Invalid language mode '{language}'. Use 'english' or 'japanese'."}, 400
|
||||
return JSONResponse(status_code=400, content={"status": "error", "message": f"Invalid language mode '{language}'. Use 'english' or 'japanese'."})
|
||||
|
||||
globals.LANGUAGE_MODE = language.lower()
|
||||
model_used = globals.JAPANESE_TEXT_MODEL if language.lower() == "japanese" else globals.TEXT_MODEL
|
||||
|
||||
Reference in New Issue
Block a user