Files
accounted/components/reports/api-error.ts
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

21 lines
850 B
TypeScript

/**
* Small, shared readers for the `{ error }` envelope the report API routes
* return. Deliberately NOT lib/errors getErrorMessage: that one rewrites known
* patterns into user-facing Swedish, these just pick the string out.
*/
/** A string error is itself; an object with a string `message` yields it; else the fallback. */
export function parseApiError(error: unknown, fallback: string): string {
if (typeof error === 'string') return error
if (error && typeof error === 'object') {
const message = (error as { message?: unknown }).message
if (typeof message === 'string') return message
}
return fallback
}
/** parseApiError applied to a JSON body's `error` field. */
export function apiErrorMessage(json: unknown, fallback: string): string {
return parseApiError((json as { error?: unknown } | null)?.error, fallback)
}