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 @@
|
||||
"""GPU selection routes."""
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger('api')
|
||||
@@ -22,7 +23,7 @@ async def select_gpu(request: Request):
|
||||
gpu = data.get("gpu", "nvidia").lower()
|
||||
|
||||
if gpu not in ["nvidia", "amd"]:
|
||||
return {"status": "error", "message": "Invalid GPU selection. Must be 'nvidia' or 'amd'"}
|
||||
return JSONResponse(status_code=400, content={"status": "error", "message": "Invalid GPU selection. Must be 'nvidia' or 'amd'"})
|
||||
|
||||
try:
|
||||
from config_manager import config_manager
|
||||
@@ -32,7 +33,7 @@ async def select_gpu(request: Request):
|
||||
logger.info(f"GPU Selection: Switched to {gpu.upper()} GPU")
|
||||
return {"status": "ok", "message": f"Switched to {gpu.upper()} GPU", "gpu": gpu}
|
||||
else:
|
||||
return {"status": "error", "message": "Failed to save GPU state"}
|
||||
return JSONResponse(status_code=500, content={"status": "error", "message": "Failed to save GPU state"})
|
||||
except Exception as e:
|
||||
logger.error(f"GPU Selection Error: {e}")
|
||||
return {"status": "error", "message": str(e)}
|
||||
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
|
||||
|
||||
Reference in New Issue
Block a user