fusion44 / blitz_api

A management backend for the RaspiBlitz project written in Python / FastAPI
MIT License
18 stars 18 forks source link

Error cases while fetching warmup data for new SSE clients aren't handled properly #245

Open fusion44 opened 5 months ago

fusion44 commented 5 months ago

Currently, the warm-up code assumes that a BaseModel will be returned at all times. Actually an HTTPException can be returned on error.

code: https://github.com/fusion44/blitz_api/blob/b7e9ae29fbcb72b85dc4dea53262c889e82177e8/app/main.py#L303

refs https://github.com/raspiblitz/raspiblitz/issues/4437

fusion44 commented 5 months ago

If something happend during fetching of the warm-up data the log files will now properly print the error:

Feb 25 08:27:58 python[2332042]: 2024-02-25 08:27:58 | ❌ | main.py:290 | Error while fetching warmup_data for system_info: 410: Something bad happened

In this example, the code raises the following exception.

        raise HTTPException(status.HTTP_410_GONE, detail="Something bad happened")

The client will receive an event with the following data:

event: system_info
data: {"error": "410: Something bad happened"}

@cstenglein You might have to add a code path for this case. Is this OK client side or would you prefer the error format like this:

event: system_info
data: {
  "error": {
    "status": 410,
    "message":  "Something bad happened"
   }
}