From bde0849f9ebd8dac1d0d9b18204faa7b9de7a571 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Fri, 5 Aug 2022 19:05:48 +0300 Subject: Add handling for random 404 errors --- alarmpy/alarmpy.py | 13 ++++++++----- 1 file 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 -- cgit v1.3.1