From 4d1e5923656cf6d9950c80c3708609017b9e4185 Mon Sep 17 00:00:00 2001 From: Dorian Date: Sun, 8 Mar 2026 21:44:17 +0000 Subject: [PATCH] refactor: standardize error handling with toError() helper Co-Authored-By: Claude Opus 4.6 --- server/src/engine/fight-loop.ts | 4 ++-- server/src/engine/orchestrator.ts | 3 ++- server/src/routes/bets.ts | 3 ++- server/src/routes/tournaments.ts | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/server/src/engine/fight-loop.ts b/server/src/engine/fight-loop.ts index 4123898..ab0a4b7 100644 --- a/server/src/engine/fight-loop.ts +++ b/server/src/engine/fight-loop.ts @@ -1,7 +1,7 @@ import { db, schema } from '../db/index.js' import { runMockFight } from './mock.js' import { eq } from 'drizzle-orm' -import { pick } from '../lib/utils.js' +import { pick, toError } from '../lib/utils.js' import { fightEvents } from './events.js' export interface FightResult { @@ -137,7 +137,7 @@ export async function startFightLoop(options: FightLoopOptions = {}): Promise { 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) } }) diff --git a/server/src/routes/tournaments.ts b/server/src/routes/tournaments.ts index f3baf04..5fbdea5 100644 --- a/server/src/routes/tournaments.ts +++ b/server/src/routes/tournaments.ts @@ -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) } })