refactor: standardize error handling with toError() helper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 21:44:17 +00:00
co-authored by Claude Opus 4.6
parent ea716c1f0e
commit 4d1e592365
4 changed files with 9 additions and 6 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import { Hono } from 'hono'
import { toError } from '../lib/utils.js'
import { db, schema } from '../db/index.js'
import { eq, desc } from 'drizzle-orm'
import { calculateOdds } from '../engine/odds.js'
@@ -104,7 +105,7 @@ betsRouter.post('/place', rateLimit(60_000, 10), async (c) => {
potentialPayout: bet.potentialPayout,
})
} catch (err: unknown) {
return c.json({ error: err instanceof Error ? err.message : String(err) }, 400)
return c.json({ error: toError(err).message }, 400)
}
})
+3 -2
View File
@@ -1,6 +1,7 @@
import { Hono } from 'hono'
import { db, schema } from '../db/index.js'
import { eq } from 'drizzle-orm'
import { toError } from '../lib/utils.js'
import {
createTournament,
joinTournament,
@@ -73,7 +74,7 @@ tournamentsRouter.post('/:id/join', async (c) => {
const entryId = joinTournament(tournamentId, bot.id, body.paymentId)
return c.json({ entryId, botId: bot.id })
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
const message = toError(err).message
return c.json({ error: message }, 400)
}
})
@@ -92,7 +93,7 @@ tournamentsRouter.post('/:id/start', async (c) => {
const bracket = getTournamentBracket(tournamentId)
return c.json({ status: 'active', bracket })
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
const message = toError(err).message
return c.json({ error: message }, 400)
}
})