Skip to content

Commit

Permalink
update(api/config): error handling and fixes missing config default
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkarry committed Nov 28, 2023
1 parent 9a27d6e commit a99bdd8
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions retraktarr/api/arr.py
Original file line number Diff line number Diff line change
@@ -44,12 +44,6 @@ def arr_get(self, arr, endpoint, timeout):
auth=(parsed_url.username, parsed_url.password),
)
response.raise_for_status()
if response.status_code == 401:
print(
f"{arr} Error: API key incorrect. "
"Please double check your key and config file."
)
sys.exit(1)
return response
except requests.exceptions.ConnectTimeout:
print(f"{arr}: Connection Timed Out. Check your URL.")
@@ -60,6 +54,12 @@ def arr_get(self, arr, endpoint, timeout):
print(f"{arr}: {error}")
sys.exit(1)
except requests.exceptions.HTTPError as error:
if "401" in str(error):
print(
f"{arr} Error: API key incorrect. "
"Please double check your key and config file."
)
sys.exit(1)
print(f"{arr} Error:")
print(f"{arr}: {error}")
sys.exit(1)
4 changes: 4 additions & 0 deletions retraktarr/api/trakt.py
Original file line number Diff line number Diff line change
@@ -95,6 +95,10 @@ def get_trakt(self, path, args, media_type, timeout):
"\nPlease check your config and attempt the oauth command (-o) again"
)
sys.exit(1)
print(
f"Trakt.tv Error: Unexpected status code return: {response.status_code}."
)
sys.exit(1)

def get_list(self, args, media_type):
""" " gets the specified trakt list and settings (account limits)"""
3 changes: 2 additions & 1 deletion retraktarr/config.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ def __init__(self, config_file):
"username": "",
"redirect_uri": "",
"oauth2_token": "",
"oauth2_refresh": "",
}
self.conf["Radarr"] = {
"url": "",
@@ -193,7 +194,7 @@ def validate_arr_configuration(self, arr_api, trakt_api, arr, args):
print(f"Error occurred while reading the configuration values: {error}")
sys.exit(1)
if not re.match(
r"^(?:https?://)?(?:[-\w.]+)+(?::\d+)?(?:/.*)?$", arr_api.api_url
r"^(?:https?://)?(?:.+:.+@)?(?:[-\w.]+)+(?::\d+)?(?:/.*)?$", arr_api.api_url
):
print(
f"Error: Invalid configuration value. [{arr}] 'url' does not match a URL pattern."

0 comments on commit a99bdd8

Please sign in to comment.