mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 06:40:50 +00:00
release: v1.32.0 — hardening and scalability (#580)
* release: prepare v1.32.0 * test: stabilize water capture re-entry
This commit is contained in:
1 parent
b01822be48
commit
62eb431d66
372 files changed
+25178
-8561
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { ApiError } from "./api-fetch";
|
||||
|
||||
type Translate = (key: string) => string;
|
||||
|
||||
/**
|
||||
* Resolve an API envelope's stable error code through the locale catalog.
|
||||
* Missing/unknown codes, network failures, and non-API errors deliberately
|
||||
* collapse to the caller's safe domain fallback; server prose is never shown.
|
||||
*/
|
||||
export function localizedApiError(
|
||||
error: unknown,
|
||||
t: Translate,
|
||||
fallbackKey: string,
|
||||
): string {
|
||||
if (error instanceof ApiError) {
|
||||
const errorCode = error.meta?.errorCode;
|
||||
if (typeof errorCode === "string") {
|
||||
const key = `apiErrors.${errorCode}`;
|
||||
const translated = t(key);
|
||||
if (translated !== key) return translated;
|
||||
}
|
||||
}
|
||||
|
||||
return t(fallbackKey);
|
||||
}
|
||||
Reference in new issue
Block a user