From a9ef04d102bd6385134f681e259b940274d4c9de Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 25 Mar 2026 16:43:58 -0500 Subject: [PATCH 1/2] fix: use server-side pagination and fix limit=500 exceeding API max - Switch from client-side pagination (fetch all, slice) to server-side (pass limit/offset/progress params to API) - Fixes limit=500 rejection (API max is 100) - Footer now shows total_count from API response - progress=close filter delegated to API instead of client-side Co-Authored-By: Claude Opus 4.6 (1M context) --- cogs/refractor.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/cogs/refractor.py b/cogs/refractor.py index 410adb3..a1f2f63 100644 --- a/cogs/refractor.py +++ b/cogs/refractor.py @@ -167,13 +167,17 @@ class Refractor(commands.Cog): ) return - params = [("team_id", team["id"]), ("limit", 500)] + page = max(1, page) + offset = (page - 1) * PAGE_SIZE + params = [("team_id", team["id"]), ("limit", PAGE_SIZE), ("offset", offset)] if card_type: params.append(("card_type", card_type)) if season is not None: params.append(("season", season)) if tier is not None: params.append(("tier", tier)) + if progress: + params.append(("progress", progress)) data = await db_get("refractor/cards", params=params) if not data: @@ -183,21 +187,23 @@ class Refractor(commands.Cog): return items = data if isinstance(data, list) else data.get("items", []) + total_count = ( + data.get("count", len(items)) if isinstance(data, dict) else len(items) + ) if not items: - await interaction.edit_original_response( - content="No refractor data found for your team." - ) - return - - if progress == "close": - items = apply_close_filter(items) - if not items: + if progress == "close": await interaction.edit_original_response( content="No cards are currently close to a tier advancement." ) - return + else: + await interaction.edit_original_response( + content="No refractor data found for your team." + ) + return - page_items, total_pages = paginate(items, page) + total_pages = max(1, (total_count + PAGE_SIZE - 1) // PAGE_SIZE) + page = min(page, total_pages) + page_items = items lines = [format_refractor_entry(state) for state in page_items] embed = discord.Embed( @@ -205,7 +211,9 @@ class Refractor(commands.Cog): description="\n\n".join(lines), color=0x6F42C1, ) - embed.set_footer(text=f"Page {page}/{total_pages} · {len(items)} card(s) total") + embed.set_footer( + text=f"Page {page}/{total_pages} · {total_count} card(s) total" + ) await interaction.edit_original_response(embed=embed) -- 2.25.1 From 1c21f674c2eab52b7273a06f83519c2a8ce55c6d Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 25 Mar 2026 16:44:20 -0500 Subject: [PATCH 2/2] fix: add error logging and user-facing message for API failures - Log API error detail when refractor endpoint returns an error - Show "Something went wrong" instead of misleading "No refractor data" - Log empty response case for debugging Co-Authored-By: Claude Opus 4.6 (1M context) --- cogs/refractor.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cogs/refractor.py b/cogs/refractor.py index a1f2f63..00ac2b7 100644 --- a/cogs/refractor.py +++ b/cogs/refractor.py @@ -181,11 +181,24 @@ class Refractor(commands.Cog): data = await db_get("refractor/cards", params=params) if not data: + logger.error( + "Refractor API returned empty response for team %s", team["id"] + ) await interaction.edit_original_response( content="No refractor data found for your team." ) return + # API error responses contain "detail" key + if isinstance(data, dict) and "detail" in data: + logger.error( + "Refractor API error for team %s: %s", team["id"], data["detail"] + ) + await interaction.edit_original_response( + content="Something went wrong fetching refractor data. Please try again later." + ) + return + items = data if isinstance(data, list) else data.get("items", []) total_count = ( data.get("count", len(items)) if isinstance(data, dict) else len(items) -- 2.25.1