sonda/web/src/pages/admin/errorText.ts
tgiachi 3dd85fc230 feat(web): admin layout, library list, add form and scan panel
The admin frame shows its sections only to an admin and asks nothing of the server for anyone else. Libraries can be added, edited (only what changed is sent) and removed after a confirmation that says the music on disk is never touched; a scan can be started for one library or all, optionally reading every file again, and the panel follows it and shows the summary, with the files in unsupported formats standing out.
2026-11-12 14:42:54 +01:00

16 lines
657 B
TypeScript

import type { TFunction } from 'i18next'
import { ApiError } from '@/api/client'
import { errorMessageKey, i18n } from '@/i18n'
/**
* An API error in words. The first scope that has a text for its code wins, so a section can say its own
* thing for a code (a bad folder) and leave the rest to the shared texts; then the generic ones.
*/
export function errorText(t: TFunction, error: unknown, scopes: string[] = ['admin.errors']): string {
const code = error instanceof ApiError ? error.code : 'unknown'
for (const scope of scopes) {
const key = `${scope}.${code}`
if (i18n.exists(key)) return t(key)
}
return t(errorMessageKey(code))
}