diff options
| author | Yuval Adam <_@yuv.al> | 2022-08-05 19:05:48 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2022-08-05 19:05:48 +0300 |
| commit | bde0849f9ebd8dac1d0d9b18204faa7b9de7a571 (patch) | |
| tree | 69fc9c41ed105c93231968f9687888856694dff4 | |
| parent | b238cd4298946748a1b8fc2882323040066c19e4 (diff) | |
Add handling for random 404 errors
| -rw-r--r-- | alarmpy/alarmpy.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/alarmpy/alarmpy.py b/alarmpy/alarmpy.py index c43ff6c..1d090b3 100644 --- a/alarmpy/alarmpy.py +++ b/alarmpy/alarmpy.py @@ -114,11 +114,14 @@ class Alarm: def fetch(self): try: res = self.session.get(self.URL, headers=self.HEADERS, timeout=1) - if not res.ok and "Access Denied" in res.text: - self.output_error( - "API endpoint has denied access. This might be due to geolocation limitations, please try running from an Israeli-based IP or proxy." - ) - exit(1) + if not res.ok: + if "Access Denied" in res.text: + self.output_error( + "API endpoint has denied access. This might be due to geolocation limitations, please try running from an Israeli-based IP or proxy." + ) + exit(1) + else: + raise Exception("HTTP request has failed") from e return res.content except requests.Timeout as e: raise Exception("HTTP request timed out") from e |
