From 3fc6721d4dd45d9515a424be7d8d1bae3e9e1956 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Thu, 19 Mar 2026 12:01:46 -0500 Subject: [PATCH] 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 --- app/routers_v2/season_stats.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/routers_v2/season_stats.py b/app/routers_v2/season_stats.py index eb87e59..65dd787 100644 --- a/app/routers_v2/season_stats.py +++ b/app/routers_v2/season_stats.py @@ -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(