mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 23:16:46 +00:00
819aa793ae
* fix(backups): prevent recursion in path that is backed up
* fix(share): show user currency instead of the default euro in the share page
* fix(files): show descriptive error for unsupported upload type
Unsupported file uploads showed a generic 'Upload failed' toast even
though the server already returns a descriptive 400. The client catch
blocks discarded the error and always showed t('files.uploadError').
The server now emits the i18n key 'files.uploadErrorType' as its error
message; a new translateApiError() helper resolves a server message that
is a known translation key via t() and falls back to the generic key
otherwise. Wired into the three trip-file upload catch sites.
Closes #1363
18 lines
636 B
TypeScript
18 lines
636 B
TypeScript
/**
|
|
* Resolve a server error whose message may be an i18n key.
|
|
*
|
|
* The server can return a translation key as its error message (e.g.
|
|
* `files.uploadErrorType`). `t()` returns the key unchanged when it isn't a
|
|
* known translation, so `translated === key` reliably means "not a key" — in
|
|
* that case we fall back to a generic, always-localized message.
|
|
*/
|
|
export function translateApiError(
|
|
t: (key: string) => string,
|
|
err: unknown,
|
|
fallbackKey: string,
|
|
): string {
|
|
const key = err instanceof Error ? err.message : ''
|
|
const translated = t(key)
|
|
return translated && translated !== key ? translated : t(fallbackKey)
|
|
}
|