Fix sensors/history: catch unhandled exceptions, return 502 with detail
Browse files
backend/api/routes/sensors.py
CHANGED
|
@@ -52,9 +52,15 @@ async def sensors_history(
|
|
| 52 |
hours: int = Query(24, ge=1, le=8760, description="Hours of history (1–8760)"),
|
| 53 |
hub: DataHub = Depends(get_datahub),
|
| 54 |
):
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
hours: int = Query(24, ge=1, le=8760, description="Hours of history (1–8760)"),
|
| 53 |
hub: DataHub = Depends(get_datahub),
|
| 54 |
):
|
| 55 |
+
try:
|
| 56 |
+
result = hub.vine_sensors.get_history(
|
| 57 |
+
device_type=type.value,
|
| 58 |
+
area=area.value if area else "treatment",
|
| 59 |
+
hours_back=hours,
|
| 60 |
+
)
|
| 61 |
+
return _check_error(result, "sensor history")
|
| 62 |
+
except HTTPException:
|
| 63 |
+
raise
|
| 64 |
+
except Exception as exc:
|
| 65 |
+
log.error("Sensor history failed: %s", exc, exc_info=True)
|
| 66 |
+
raise HTTPException(status_code=502, detail=f"Sensor history unavailable: {exc}")
|