🐛 (api.py): Raise correct error when timeout #45

Open
Zerka30 wants to merge 2 commits from Zerka30/return-timeout into master

View file

@ -500,13 +500,16 @@ class UptimeKumaApi(object):
return deepcopy(self._event_data[event].copy()) return deepcopy(self._event_data[event].copy())
def _call(self, event, data=None) -> Any: def _call(self, event, data=None) -> Any:
r = self.sio.call(event, data, timeout=self.timeout) try:
r = self.sio.call(event, data, timeout=self.timeout)
except socketio.exceptions.TimeoutError:
lucasheld commented 2023-08-29 23:03:11 +02:00 (Migrated from github.com)
Review

The response of self.sio.call is not always a dict (for example api.need_setup). In this case r.pop("ok") fails. You have deleted the code that checks if the response type is a dict.

Also you have deleted the code that checks the r["ok"] value. The UptimeKumaException is now no longer raised when Uptime Kuma responds with an error message (when r["ok"] is false).

The response of `self.sio.call` is not always a dict (for example `api.need_setup`). In this case `r.pop("ok")` fails. You have deleted the code that checks if the response type is a dict. Also you have deleted the code that checks the `r["ok"]` value. The UptimeKumaException is now no longer raised when Uptime Kuma responds with an error message (when `r["ok"]` is false).
raise Timeout(f"Timed out while waiting for event {event}")
if isinstance(r, dict) and "ok" in r: if isinstance(r, dict) and "ok" in r:
if not r["ok"]: if not r["ok"]:
raise UptimeKumaException(r.get("msg")) raise UptimeKumaException(r.get("msg"))
r.pop("ok") r.pop("ok")
return r return r
# event handlers # event handlers
def _event_connect(self) -> None: def _event_connect(self) -> None: