From 91ad893223eb1d23c080d83fb97bff09f40aa4bc Mon Sep 17 00:00:00 2001 From: Zerka30 Date: Thu, 10 Aug 2023 11:45:23 +0200 Subject: [PATCH 1/2] :bug: (api.py): Raise correct error when timeout --- uptime_kuma_api/api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uptime_kuma_api/api.py b/uptime_kuma_api/api.py index 9912dd3..9013d98 100644 --- a/uptime_kuma_api/api.py +++ b/uptime_kuma_api/api.py @@ -500,11 +500,14 @@ class UptimeKumaApi(object): return deepcopy(self._event_data[event].copy()) def _call(self, event, data=None) -> Any: - r = self.sio.call(event, data, timeout=self.timeout) - if isinstance(r, dict) and "ok" in r: - if not r["ok"]: - raise UptimeKumaException(r.get("msg")) + try: + r = self.sio.call(event, data, timeout=self.timeout) r.pop("ok") + except socketio.exceptions.TimeoutError: + raise Timeout(f"Timed out while waiting for event {event}") + except Exception as e: + raise UptimeKumaException(r.get("msg")) + return r # event handlers -- 2.47.0 From d56ffcc774d8e8bd24007b5a72945d541023b2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20=22Zerka=22=20H?= Date: Thu, 31 Aug 2023 12:14:41 +0200 Subject: [PATCH 2/2] :bug: (api.py): Fix to work has expected --- uptime_kuma_api/api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/uptime_kuma_api/api.py b/uptime_kuma_api/api.py index 9013d98..5de7fa7 100644 --- a/uptime_kuma_api/api.py +++ b/uptime_kuma_api/api.py @@ -502,14 +502,14 @@ class UptimeKumaApi(object): def _call(self, event, data=None) -> Any: try: r = self.sio.call(event, data, timeout=self.timeout) - r.pop("ok") except socketio.exceptions.TimeoutError: raise Timeout(f"Timed out while waiting for event {event}") - except Exception as e: - raise UptimeKumaException(r.get("msg")) - + if isinstance(r, dict) and "ok" in r: + if not r["ok"]: + raise UptimeKumaException(r.get("msg")) + r.pop("ok") return r - + # event handlers def _event_connect(self) -> None: -- 2.47.0