Skip to content

fix(api): handle nulls in ranking query and log error stack trace (#84) - #126

Open
angelTomo9 wants to merge 2 commits into
Bitcoindefi:mainfrom
angelTomo9:fix-api-ranking-null-handling-1787648503145
Open

fix(api): handle nulls in ranking query and log error stack trace (#84)#126
angelTomo9 wants to merge 2 commits into
Bitcoindefi:mainfrom
angelTomo9:fix-api-ranking-null-handling-1787648503145

Conversation

@angelTomo9

Copy link
Copy Markdown

Closes #84

Summary of Changes

Fixes HTTP 500 errors on GET /ranking when executed against clean or partially populated databases and adds server-side error stack logging.

Root Cause & Solution

  • In api/src/repositories/characters.ts, the listCharacterRanking SQL query evaluated (c.ciudadanos_matados + c.criminales_matados) without COALESCE. If either field was null, the arithmetic expression yielded NULL, causing ordering errors and unexpected query behavior.
  • Added COALESCE(c.ciudadanos_matados, 0) + COALESCE(c.criminales_matados, 0) and COALESCE(c.id_last_head, 0) guards.
  • Updated toRankingCharacterResponse to defensively coerce numeric and string properties.
  • Added console.error("Error in /ranking handler:", error) inside api/src/server.ts to capture full error stack traces in logs.

Comment thread api/src/repositories/characters.ts Outdated
@gitar-bot

gitar-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Fixes HTTP 500 ranking query errors by adding COALESCE guards for null values and preserving the CharacterFaction union type, addressing the String() coercion issue. No issues found.

✅ 1 resolved
Bug: String() on faction breaks CharacterFaction union type

📄 api/src/repositories/characters.ts:338
faction: String(character.faction ?? "none") produces a plain string, but RankingCharacterResponse.faction is typed as the union CharacterFaction = "none" | "armada" | "caos". string is not assignable to that literal union, so this line fails TypeScript compilation (TS2322). Since the SQL already uses COALESCE(c.faction, 'none') and the record field is non-nullable CharacterFaction, drop the String() wrapper: faction: character.faction ?? "none",.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 7 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

El endpoint de ranking devuelve 500 en un entorno limpio

1 participant