safraeli commited on
Commit
b09e6cd
·
verified ·
1 Parent(s): e36fa09

Fix sensors/history: catch unhandled exceptions, return 502 with detail

Browse files
Files changed (1) hide show
  1. backend/api/routes/sensors.py +12 -6
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
- result = hub.vine_sensors.get_history(
56
- device_type=type.value,
57
- area=area.value if area else "treatment",
58
- hours_back=hours,
59
- )
60
- return _check_error(result, "sensor history")
 
 
 
 
 
 
 
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}")