From d54321faaa589b6cfdb7d7a55efa05b8d07d67c8 Mon Sep 17 00:00:00 2001 From: Cesar E Garza Date: Sun, 25 Jan 2026 21:57:26 -0600 Subject: [PATCH] Enhance error handling in tournament teams extraction from SendouQ API This commit improves the error handling when extracting tournament teams from the SendouQ API response. It adds support for parsing JSON strings and logs errors related to key access and JSON decoding, ensuring better traceability and robustness in the event of unexpected response structures. --- src/fast_api_app/routes/sendou_proxy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fast_api_app/routes/sendou_proxy.py b/src/fast_api_app/routes/sendou_proxy.py index 11cc164..2243bd4 100644 --- a/src/fast_api_app/routes/sendou_proxy.py +++ b/src/fast_api_app/routes/sendou_proxy.py @@ -202,9 +202,14 @@ async def get_tournament_teams( ) # Extract teams from tournament.ctx.teams + # Note: data["data"] is a JSON string that needs to be parsed try: - teams = data["data"]["tournament"]["ctx"]["teams"] - except (KeyError, TypeError): + inner_data = data["data"] + if isinstance(inner_data, str): + inner_data = orjson.loads(inner_data) + teams = inner_data["tournament"]["ctx"]["teams"] + except (KeyError, TypeError, orjson.JSONDecodeError) as e: + logger.error("Failed to extract teams from response: %s", e) raise HTTPException( status_code=502, detail="Unexpected response structure from sendou.ink",