Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions modules/apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import time

import requests

from modules import util
from modules.util import Failed

Expand All @@ -25,10 +27,9 @@ def check_api_url(self):
"""Check if the API URL is valid"""
# Check the response using application.json get header
status_endpoint = self.api_url + "/status"
response = self.config.get(status_endpoint, headers={"Accept": "application/json"})
if response.status_code != 200:
raise Failed(
f"Apprise Error: Unable to connect to Apprise using {status_endpoint} "
f"with status code {response.status_code}: {response.reason}"
)
return response
try:
response = self.config.get(status_endpoint, headers={"Accept": "application/json"})
response.raise_for_status()
return response
except requests.exceptions.RequestException as e:
raise Failed(f"Apprise Error: Unexpected error connecting to {status_endpoint} ({e})")
14 changes: 12 additions & 2 deletions modules/notifiarr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import time
from json import JSONDecodeError

import requests

from modules import util
from modules.util import Failed

Expand All @@ -21,7 +23,11 @@ def __init__(self, config, params):
self.instance = params["instance"]
self.url = f"{self.BASE_URL}/{self.API_VERSION}/"
logger.secret(self.apikey)
response = self.config.get(f"{self.url}user/qbitManage/", headers=self.header, params={"fetch": "settings"})
try:
response = self.config.get(f"{self.url}user/qbitManage/", headers=self.header, params={"fetch": "settings"})
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise Failed(f"Notifiarr error: Unable to connect to Notifiarr ({e})")
response_json = None
try:
response_json = response.json()
Expand All @@ -37,6 +43,10 @@ def __init__(self, config, params):
def notification(self, json):
"""Send notification to Notifiarr"""
params = {"qbit_client": self.config.data["qbt"]["host"], "instance": self.instance}
response = self.config.get(f"{self.url}notification/qbitManage/", json=json, headers=self.header, params=params)
try:
response = self.config.get(f"{self.url}notification/qbitManage/", json=json, headers=self.header, params=params)
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise Failed(f"Notifarr error: Unable to send notification ({e})")
time.sleep(1) # Pause for 1 second before sending the next request
return response