diff --git a/modules/config.py b/modules/config.py index 302ab7d..023e678 100644 --- a/modules/config.py +++ b/modules/config.py @@ -110,10 +110,7 @@ class Config: }) except Failed as e: logger.error(e) - notifiarr_error = str(e) - if '525' in notifiarr_error: - self.NotifiarrFactory = notifiarr_error - logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is (None or notifiarr_error) else 'Successful'}") + logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is None else 'Successful'}") else: logger.warning("Config Warning: notifiarr attribute not found") diff --git a/modules/notifiarr.py b/modules/notifiarr.py index ad07c0e..47791e0 100644 --- a/modules/notifiarr.py +++ b/modules/notifiarr.py @@ -20,12 +20,12 @@ class Notifiarr: response = self.config.get(url) try: response_json = response.json() - except JSONDecodeError: + except JSONDecodeError as e: if response.status_code >= 400: if response.status_code == 525: raise Failed(f"Notifiarr Error (Response: 525): SSL handshake between Cloudflare and the origin web server failed.") else: - raise Failed(f"({response.status_code} [{response.reason}])") + raise Failed(e) if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"): logger.debug(f"Response: {response_json}") raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") diff --git a/modules/webhooks.py b/modules/webhooks.py index 0800399..fe01694 100644 --- a/modules/webhooks.py +++ b/modules/webhooks.py @@ -26,42 +26,47 @@ class Webhooks: logger.debug("") logger.debug(f"JSON: {json}") for webhook in list(set(webhooks)): + response = None if self.config.trace_mode: logger.debug(f"Webhook: {webhook}") if webhook == "notifiarr": if self.notifiarr is None: - raise Failed(f"Webhook attribute set to notifiarr but notifiarr attribute is not configured.") - elif '525' in self.notifiarr: - raise Failed(self.notifiarr) - url, params = self.notifiarr.get_url("notification/qbitManage/") - for x in range(6): - response = self.config.get(url, json=json, params=params) - if response.status_code < 500: - break + break + else: + url, params = self.notifiarr.get_url("notification/qbitManage/") + for x in range(6): + response = self.config.get(url, json=json, params=params) + if response.status_code < 500: + break elif webhook == "apprise": if self.apprise is None: - raise Failed(f"Webhook attribute set to apprise but apprise attribute is not configured.") - json['urls'] = self.apprise.notify_url - response = self.config.post(f"{self.apprise.api_url}/notify", json=json) + logger.warning(f"Webhook attribute set to apprise but apprise attribute is not configured.") + break + else: + json['urls'] = self.apprise.notify_url + for x in range(6): + response = self.config.post(f"{self.apprise.api_url}/notify", json=json) + if response.status_code < 500: + break else: response = self.config.post(webhook, json=json) - - skip = False - try: - response_json = response.json() - if self.config.trace_mode: - logger.debug(f"Response: {response_json}") - if "result" in response_json and response_json["result"] == "error" and "details" in response_json and "response" in response_json["details"]: - if ('trigger is not enabled' in response_json['details']['response']): - logger.debug(f"Notifiarr Warning: {response_json['details']['response']}") - skip = True - else: - raise Failed(f"Notifiarr Error: {response_json['details']['response']}") - if (response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error")) and skip == False: - raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") - except JSONDecodeError: - if response.status_code >= 400: - raise Failed(f"({response.status_code} [{response.reason}])") + if response: + skip = False + try: + response_json = response.json() + if self.config.trace_mode: + logger.debug(f"Response: {response_json}") + if "result" in response_json and response_json["result"] == "error" and "details" in response_json and "response" in response_json["details"]: + if ('trigger is not enabled' in response_json['details']['response']): + logger.debug(f"Notifiarr Warning: {response_json['details']['response']}") + skip = True + else: + raise Failed(f"Notifiarr Error: {response_json['details']['response']}") + if (response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error")) and skip == False: + raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") + except JSONDecodeError: + if response.status_code >= 400: + raise Failed(f"({response.status_code} [{response.reason}])") def start_time_hooks(self, start_time): if self.run_start_webhooks: