feat: show rejoin link when bot is already in a fight
- Track active fight IDs per bot in orchestrator (Set → Map) - Return fightId in "already in fight" error responses (409) - Frontend shows "REJOIN FIGHT" link instead of generic error Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
64273cf145
commit
e31d49898b
@@ -7,7 +7,7 @@ import { eq, desc, inArray } from 'drizzle-orm'
|
||||
import { ARENAS } from '../engine/arenas.js'
|
||||
import { runMockFight, isClassicBot } from '../engine/mock.js'
|
||||
import { startFightLoop } from '../engine/fight-loop.js'
|
||||
import { runFight, runFightAsync, isInFight } from '../engine/orchestrator.js'
|
||||
import { runFight, runFightAsync, isInFight, getActiveFightId } from '../engine/orchestrator.js'
|
||||
import { fightEvents } from '../engine/events.js'
|
||||
import { botRateLimit } from '../middleware/rate-limit.js'
|
||||
import { getPendingChallenge, getPendingAnswers, submitHumanResponse } from '../engine/human-responses.js'
|
||||
@@ -233,7 +233,7 @@ fightsRouter.post('/matchmake/:botId', botRateLimit(10_000), async (c) => {
|
||||
}
|
||||
|
||||
if (isInFight(botId)) {
|
||||
return c.json({ error: 'Bot is already in a fight.' }, 400)
|
||||
return c.json({ error: 'Bot is already in a fight.', fightId: getActiveFightId(botId) }, 409)
|
||||
}
|
||||
|
||||
const allBots = await db.select()
|
||||
@@ -285,7 +285,7 @@ fightsRouter.post('/practice/:botId', botRateLimit(10_000), async (c) => {
|
||||
const bot = botRows[0]
|
||||
|
||||
if (isInFight(botId)) {
|
||||
return c.json({ error: 'Bot is already in a fight.' }, 400)
|
||||
return c.json({ error: 'Bot is already in a fight.', fightId: getActiveFightId(botId) }, 409)
|
||||
}
|
||||
|
||||
// Find all classic bots
|
||||
|
||||
@@ -31,9 +31,10 @@ queueRouter.post('/join/:botId', async (c) => {
|
||||
try {
|
||||
const fightId = await joinQueue(botId)
|
||||
return c.json({ fightId, message: 'Matched! Fight starting.' })
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
const message = err instanceof Error ? err.message : 'Queue error'
|
||||
return c.json({ error: message }, 500)
|
||||
const status = message.includes('already in a fight') ? 409 : 500
|
||||
return c.json({ error: message, fightId: err?.fightId || undefined }, status)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user