All files / web/src/app/api/realtime/voice-error route.ts

0% Statements 0/33
0% Branches 0/1
0% Functions 0/1
0% Lines 0/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
/**
 * Client-side voice error reporting endpoint.
 *
 * When the OpenAI Realtime API sends an error over the WebRTC data channel
 * (e.g. quota_exceeded), the server never sees it — the session was created
 * successfully. This endpoint lets the client report these errors so they
 * appear in server logs for admin visibility.
 *
 * POST /api/realtime/voice-error
 * Body: { code, message, source }
 */

import { withAuth } from '@/lib/auth/withAuth'

export const POST = withAuth(async (request) => {
  const body = await request.json()
  const { code, message, source } = body as {
    code?: string
    message?: string
    source?: string
  }

  const level = /quota|billing|insufficient/i.test(code ?? '') ? 'error' : 'warn'

  console[level](
    '[voice-error] Client reported %s: %s (source: %s)',
    code ?? 'unknown',
    message ?? 'no message',
    source ?? 'unknown'
  )

  return Response.json({ ok: true })
})