fix: catch DoesNotExist and return 404 for nonexistent game_id

Closes #113

Adds a specific `DoesNotExist` handler before the generic `Exception`
block in `update_game_season_stats`. Peewee's `DoesNotExist` (raised
when `StratGame.get_by_id(game_id)` finds no row) previously bubbled
through to the `except Exception` handler which included raw SQL and
params in the 500 detail string. Now returns a clean 404.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-19 12:01:46 -05:00
parent cf0b1d1d1c
commit 3fc6721d4d

View File

@ -52,9 +52,12 @@ async def update_game_season_stats(
raise HTTPException(status_code=401, detail="Unauthorized")
from ..services.season_stats import update_season_stats
from ..db_engine import DoesNotExist
try:
result = update_season_stats(game_id, force=force)
except DoesNotExist:
raise HTTPException(status_code=404, detail=f"Game {game_id} not found")
except Exception as exc:
logger.error("update-game/%d failed: %s", game_id, exc, exc_info=True)
raise HTTPException(