| import { ApiRequestError, getLastRequestId } from '../api/client' |
| import type { MessageKey } from '../i18n/en' |
|
|
| type Translate = (key: MessageKey, vars?: Record<string, string | number>) => string |
|
|
| |
| |
| |
| |
| export function localizeError(e: unknown, t: Translate, fallbackKey: MessageKey): string { |
| if (e instanceof ApiRequestError) { |
| if (e.status === 0) { |
| return t(e.message === 'request timed out' ? 'error.timeout' : 'error.network') |
| } |
| const rid = e.requestId ?? getLastRequestId() ?? undefined |
| return rid ? t('error.withRef', { msg: t(fallbackKey), id: rid }) : t(fallbackKey) |
| } |
| return t(fallbackKey) |
| } |
|
|
| |
| |
| |
| export function bioErrorKey(e: unknown): MessageKey | null { |
| if (!(e instanceof ApiRequestError)) return null |
| const m = (e.message || '').toLowerCase() |
| if (e.status === 422 && m.includes('face')) return 'bio.err.noFace' |
| return null |
| } |
|
|