fix(api): handle nulls in ranking query and log error stack trace (#84) - #126
fix(api): handle nulls in ranking query and log error stack trace (#84)#126angelTomo9 wants to merge 2 commits into
Conversation
Code Review ✅ Approved 1 resolved / 1 findingsFixes 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
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
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 |
Closes #84
Summary of Changes
Fixes HTTP 500 errors on
GET /rankingwhen executed against clean or partially populated databases and adds server-side error stack logging.Root Cause & Solution
api/src/repositories/characters.ts, thelistCharacterRankingSQL query evaluated(c.ciudadanos_matados + c.criminales_matados)without COALESCE. If either field was null, the arithmetic expression yieldedNULL, causing ordering errors and unexpected query behavior.COALESCE(c.ciudadanos_matados, 0) + COALESCE(c.criminales_matados, 0)andCOALESCE(c.id_last_head, 0)guards.toRankingCharacterResponseto defensively coerce numeric and string properties.console.error("Error in /ranking handler:", error)insideapi/src/server.tsto capture full error stack traces in logs.