Skip to content

Commit

Permalink
Make requests.get call timeout configurable via environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
veddevv authored Nov 4, 2024
1 parent e5ce823 commit 86d481d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vgde.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Retrieve the RAWG API key from environment variables
API_KEY = os.getenv('RAWG_API_KEY')
BASE_URL = 'https://api.rawg.io/api'
REQUEST_TIMEOUT = int(os.getenv('REQUEST_TIMEOUT', 10)) # Default to 10 seconds if not set

class MissingAPIKeyError(Exception):
"""Custom exception for missing API key."""
Expand Down Expand Up @@ -76,7 +77,7 @@ def get_game_info(game_name):
}

try:
response = requests.get(url, params=params, timeout=10)
response = requests.get(url, params=params, timeout=REQUEST_TIMEOUT)
response.raise_for_status() # Raise an HTTPError for bad responses
except requests.Timeout:
logging.error("The request timed out while trying to fetch game information.")
Expand Down

0 comments on commit 86d481d

Please sign in to comment.