odds error handling so it doesn't get stuck

This commit is contained in:
Chuck
2025-07-22 16:00:55 -05:00
parent 5e7e9fa2ae
commit 26a518e63f

View File

@@ -307,6 +307,12 @@ class OddsTickerManager:
url = f"https://site.api.espn.com/apis/site/v2/sports/{sport}/{league}/scoreboard?dates={date}"
logger.debug(f"Fetching {league} games from ESPN API for date: {date}")
response = requests.get(url, timeout=10)
# Handle potential 400 error for MiLB, which seems to be an invalid endpoint
if league == 'milb' and response.status_code == 400:
logger.warning(f"Received a 400 Bad Request for MiLB on {date}. This league may no longer be supported by the API. Skipping.")
continue # Skip to the next date or league
response.raise_for_status()
data = response.json()
for event in data.get('events', []):
@@ -380,6 +386,8 @@ class OddsTickerManager:
# Stop if we have enough games for the league (when not showing favorite teams only)
if not self.show_favorite_teams_only and max_games_per_league and games_found >= max_games_per_league:
break
except requests.exceptions.HTTPError as http_err:
logger.error(f"HTTP error occurred while fetching games for {league} on {date}: {http_err}")
except Exception as e:
logger.error(f"Error fetching games for {league_config.get('league', 'unknown')} on {date}: {e}", exc_info=True)
if not self.show_favorite_teams_only and max_games_per_league and games_found >= max_games_per_league: