Files
Nexus/frontend/src/utils/apiError.ts
T

16 lines
519 B
TypeScript
Raw Normal View History

import { ApiError } from '@/api'
import { formatValidationDetail } from '@/utils/validationErrorFormat'
/** Turn FastAPI error bodies into a human-readable string. */
export function formatApiError(e: unknown, fallback: string): string {
if (e instanceof ApiError) {
const d = (e as ApiError & { detail?: unknown }).detail ?? e.message
return formatValidationDetail(d, e.message || fallback)
}
if (e instanceof Error) {
const msg = e.message.trim()
return msg || fallback
}
return fallback
}