fix: server-side pagination and error handling for /refractor status #123
@ -167,37 +167,56 @@ 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:
|
||||
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)
|
||||
)
|
||||
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 +224,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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user