Return 200 with empty state instead of 503/404
Browse files
backend/api/routes/control.py
CHANGED
|
@@ -20,10 +20,7 @@ async def control_status():
|
|
| 20 |
data = redis.get_json("control:last_tick")
|
| 21 |
if data:
|
| 22 |
return data
|
| 23 |
-
|
| 24 |
-
status_code=503,
|
| 25 |
-
detail="No tick result available (worker may not have run yet)",
|
| 26 |
-
)
|
| 27 |
|
| 28 |
|
| 29 |
@router.get("/plan")
|
|
@@ -41,7 +38,7 @@ async def control_plan():
|
|
| 41 |
with open(DAILY_PLAN_PATH) as f:
|
| 42 |
return json.load(f)
|
| 43 |
except FileNotFoundError:
|
| 44 |
-
|
| 45 |
except Exception as exc:
|
| 46 |
log.error("Failed to load plan from file: %s", exc)
|
| 47 |
raise HTTPException(status_code=500, detail="Plan loading failed")
|
|
@@ -55,10 +52,7 @@ async def control_budget():
|
|
| 55 |
data = redis.get_json("control:budget")
|
| 56 |
if data:
|
| 57 |
return data
|
| 58 |
-
|
| 59 |
-
status_code=503,
|
| 60 |
-
detail="No budget data available",
|
| 61 |
-
)
|
| 62 |
|
| 63 |
|
| 64 |
_tracker_cache: dict = {"data": None, "expires": 0.0}
|
|
|
|
| 20 |
data = redis.get_json("control:last_tick")
|
| 21 |
if data:
|
| 22 |
return data
|
| 23 |
+
return {"status": "waiting", "message": "Worker has not run yet"}
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
@router.get("/plan")
|
|
|
|
| 38 |
with open(DAILY_PLAN_PATH) as f:
|
| 39 |
return json.load(f)
|
| 40 |
except FileNotFoundError:
|
| 41 |
+
return {"status": "waiting", "message": "No plan generated yet", "slots": []}
|
| 42 |
except Exception as exc:
|
| 43 |
log.error("Failed to load plan from file: %s", exc)
|
| 44 |
raise HTTPException(status_code=500, detail="Plan loading failed")
|
|
|
|
| 52 |
data = redis.get_json("control:budget")
|
| 53 |
if data:
|
| 54 |
return data
|
| 55 |
+
return {"status": "waiting", "message": "No budget computed yet"}
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
_tracker_cache: dict = {"data": None, "expires": 0.0}
|