From 684b345e19808d758def3ff57da35484c02c2218 Mon Sep 17 00:00:00 2001 From: Daan Koning Date: Sun, 22 Jan 2023 22:18:10 +0100 Subject: [PATCH] Improve error handling: introduce generic --- logic.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/logic.py b/logic.py index cf470e8..dbda4e5 100644 --- a/logic.py +++ b/logic.py @@ -5,11 +5,15 @@ import requests BASE_URL = "https://api.the-odds-api.com/v4" -class AuthenticationException(RuntimeError): +class APIException(RuntimeError): pass -class RateLimitException(RuntimeError): +class AuthenticationException(APIException): + pass + + +class RateLimitException(APIException): pass @@ -18,6 +22,8 @@ def handle_faulty_response(response: requests.Response): raise AuthenticationException("Failed to authenticate with the API. is the API key valid?") elif response.status_code == 429: raise RateLimitException("Encountered API rate limit.") + else: + raise APIException("Unknown issue arose while trying to access the API.") def get_sports(key: str) -> set[str]: