refactor(web/api): errCode + errMessage helpers; 41 sites migrated (W1)

This commit is contained in:
2026-05-07 22:17:45 -04:00
parent 965df28127
commit 9c91a342e2
16 changed files with 138 additions and 70 deletions
+18
View File
@@ -0,0 +1,18 @@
import { copyForCode } from './error-copy';
/**
* Returns the `code` field from an unknown error value, or 'unknown'
* when the value isn't shaped like { code: string }.
*/
export function errCode(err: unknown): string {
return (err as { code?: string })?.code ?? 'unknown';
}
/**
* Returns user-facing copy for an unknown error value. Looks up the
* error's code in the error-copy map; falls back to the supplied
* fallback (default: "Something went wrong.") when the code is unknown.
*/
export function errMessage(err: unknown, fallback = 'Something went wrong.'): string {
return copyForCode(errCode(err)) ?? fallback;
}