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 @@
|
||||
"""Configuration management routes: get/set/reset/validate config."""
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
import globals
|
||||
from utils.logger import get_logger
|
||||
|
||||
@@ -24,7 +25,7 @@ async def get_full_config():
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get config: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
|
||||
@router.get("/config/static")
|
||||
@@ -41,7 +42,7 @@ async def get_static_config():
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get static config: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
|
||||
@router.get("/config/runtime")
|
||||
@@ -59,7 +60,7 @@ async def get_runtime_config():
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get runtime config: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
|
||||
@router.post("/config/set")
|
||||
@@ -80,7 +81,7 @@ async def set_config_value(request: Request):
|
||||
persist = data.get("persist", True)
|
||||
|
||||
if not key_path:
|
||||
return {"success": False, "error": "key_path is required"}
|
||||
return JSONResponse(status_code=400, content={"success": False, "error": "key_path is required"})
|
||||
|
||||
from config_manager import config_manager
|
||||
config_manager.set(key_path, value, persist=persist)
|
||||
@@ -114,7 +115,7 @@ async def set_config_value(request: Request):
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to set config: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
|
||||
@router.post("/config/reset")
|
||||
@@ -143,7 +144,7 @@ async def reset_config(request: Request):
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to reset config: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
|
||||
@router.post("/config/validate")
|
||||
@@ -163,7 +164,7 @@ async def validate_config_endpoint():
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to validate config: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
|
||||
@router.get("/config/state")
|
||||
@@ -180,4 +181,4 @@ async def get_config_state():
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get config state: {e}")
|
||||
return {"success": False, "error": str(e)}
|
||||
return JSONResponse(status_code=500, content={"success": False, "error": str(e)})
|
||||
|
||||
Reference in New Issue
Block a user