2026-06-01 12:17:47 +08:00
|
|
|
import { ApiError } from '@/api'
|
2026-06-08 23:28:26 +08:00
|
|
|
import { formatValidationDetail } from '@/utils/validationErrorFormat'
|
2026-06-01 12:17:47 +08:00
|
|
|
|
|
|
|
|
/** 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
|
2026-06-08 23:28:26 +08:00
|
|
|
return formatValidationDetail(d, e.message || fallback)
|
2026-06-01 12:17:47 +08:00
|
|
|
}
|
2026-06-08 23:28:26 +08:00
|
|
|
if (e instanceof Error) {
|
|
|
|
|
const msg = e.message.trim()
|
|
|
|
|
return msg || fallback
|
|
|
|
|
}
|
|
|
|
|
return fallback
|
2026-06-01 12:17:47 +08:00
|
|
|
}
|