Skip to content

Commit

Permalink
Improve error handling and input validation (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
veddevv authored Nov 2, 2024
1 parent eb37a51 commit 86ffe82
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions vgde.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def sanitize_game_name(game_name):
"""
if not isinstance(game_name, str):
raise InvalidInputError("Invalid input. Game name must be a string.")

game_name = game_name.strip()

if not game_name:
raise InvalidInputError("Invalid input. Please enter a non-empty game name.")

if len(game_name) > 100:
raise InvalidInputError("Invalid input. Game name is too long.")

if not re.match("^[a-zA-Z0-9\s]+$", game_name):
raise InvalidInputError("Invalid input. Game name contains invalid characters.")

return game_name

def check_api_key():
Expand Down Expand Up @@ -73,7 +73,7 @@ def get_game_info(game_name):
'key': API_KEY,
'search': game_name
}

try:
response = requests.get(url, params=params, timeout=10)
response.raise_for_status() # Raise an HTTPError for bad responses
Expand All @@ -92,7 +92,7 @@ def get_game_info(game_name):
except requests.RequestException as e:
logging.error(f"An unexpected error occurred while trying to fetch game information: {e}")
return None

try:
data = response.json()
except ValueError as e:
Expand Down

0 comments on commit 86ffe82

Please sign in to comment.