Skip to content

Commit

Permalink
Update vgde.py
Browse files Browse the repository at this point in the history
  • Loading branch information
veddevv authored Dec 20, 2024
1 parent 05f18b1 commit cb31c6e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions vgde.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def check_api_key() -> None:
MissingAPIKeyError: If the API key is not set.
"""
if not API_KEY or API_KEY.strip() == "":
logging.error("API key not found. Please set the RAWG_API_KEY environment variable.")
raise MissingAPIKeyError("API key not found. Please set the RAWG_API_KEY environment variable.")

def fetch_game_data(game_name: str) -> Optional[Dict[str, object]]:
Expand All @@ -84,18 +85,16 @@ def fetch_game_data(game_name: str) -> Optional[Dict[str, object]]:
response.raise_for_status()
return response.json()
except requests.Timeout:
logging.error("The request timed out while trying to fetch game information.")
logging.error(f"The request timed out while trying to fetch game information for '{game_name}'.")
except requests.ConnectionError:
logging.error("A network problem occurred while trying to fetch game information.")
logging.error(f"A network problem occurred while trying to fetch game information for '{game_name}'.")
except requests.HTTPError as e:
if e.response.status_code == 404:
logging.error("Game not found (404).")
else:
logging.error(f"HTTP error occurred while trying to fetch game information: {e.response.status_code} - {e.response.reason}")
logging.error(f"HTTP error occurred while trying to fetch game information for '{game_name}': {e.response.status_code} - {e.response.reason}")
logging.error(f"Response content: {e.response.content}")
except requests.RequestException as e:
logging.error(f"An unexpected error occurred while trying to fetch game information: {e}")
logging.error(f"An unexpected error occurred while trying to fetch game information for '{game_name}': {e}")
except ValueError as e:
logging.error(f"JSON decoding error occurred while processing the response: {e}")
logging.error(f"JSON decoding error occurred while processing the response for '{game_name}': {e}")

return None

Expand Down

0 comments on commit cb31c6e

Please sign in to comment.