import { HttpError } from '../services/HttpService.tsx'; import { contextTakenNotice } from './contextTakenNotice'; /** * A refused video start or join, as the server's own sentence rather than "Request failed:" around it. Only a * refusal our handlers wrote (a `code` beside a `message`, no gateway error type) is read this way; anything * else returns `undefined`, so a lost connection still reads as one. */ export const videoRefusalNotice = (error: unknown, context?: string): string | undefined => { const taken = contextTakenNotice(error, context); if (taken) return taken; if (!(error instanceof HttpError) || error.awsErrorType) return undefined; const body = error.body as { code?: unknown; message?: unknown } | undefined; if (typeof body?.code !== 'string' || typeof body.message !== 'string') return undefined; return body.message.trim() || undefined; }; /** The code of a refusal our handlers wrote, read the same way as its sentence; undefined for anything else. */ export const refusalCode = (error: unknown): string | undefined => { if (!(error instanceof HttpError) || error.awsErrorType) return undefined; const code = (error.body as { code?: unknown } | undefined)?.code; return typeof code === 'string' ? code : undefined; };