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 -2
View File
@@ -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<vo
}
} catch (err) {
if (onError) {
onError(err instanceof Error ? err : new Error(String(err)))
onError(toError(err))
} else {
console.error('[fight-loop] error:', err)
}
+2 -1
View File
@@ -1,4 +1,5 @@
import { nanoid } from 'nanoid'
import { toError } from '../lib/utils.js'
import { db, schema, sqlite } from '../db/index.js'
import { eq, sql } from 'drizzle-orm'
import { randomArena, type Arena } from './arenas.js'
@@ -207,7 +208,7 @@ async function callWebhook(
} catch (err: unknown) {
const elapsed = Date.now() - start
const isAbort = err instanceof Error && err.name === 'AbortError'
console.log(`[webhook] ${url} ${isAbort ? "TIMEOUT" : "ERROR"} in ${elapsed}ms: ${err instanceof Error ? err.message : err}`)
console.log(`[webhook] ${url} ${isAbort ? "TIMEOUT" : "ERROR"} in ${elapsed}ms: ${toError(err).message}`)
return {
answer: null,
timeMs: elapsed,