refactor: standardize error handling with toError() helper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
ea716c1f0e
commit
4d1e592365
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user