mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-04 17:18:35 +02:00
Adds lib/auth-error.ts that maps backend raw English errors (invalid / expired / rate-limited / network) to user-facing copy. login.tsx and verify.tsx route their catch blocks through it with a per-screen fallback string. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
24 lines
912 B
TypeScript
24 lines
912 B
TypeScript
/**
|
|
* Map backend auth errors to user-facing strings. The backend returns raw
|
|
* English messages that are fine for logs but should not surface as-is —
|
|
* we map the known shapes to friendlier copy and fall back to the caller's
|
|
* default for anything unrecognised.
|
|
*/
|
|
export function mapAuthError(err: unknown, fallback: string): string {
|
|
if (!(err instanceof Error)) return fallback;
|
|
const msg = err.message.toLowerCase();
|
|
if (/invalid|incorrect|wrong/.test(msg)) {
|
|
return "That code didn't match. Double-check and try again.";
|
|
}
|
|
if (/expired/.test(msg)) {
|
|
return "That code has expired. Tap resend to get a new one.";
|
|
}
|
|
if (/rate.?limit|too many|throttle/.test(msg)) {
|
|
return "Too many attempts. Wait a moment and try again.";
|
|
}
|
|
if (/network|fetch|timeout|unreachable/.test(msg)) {
|
|
return "Can't reach Multica. Check your connection and retry.";
|
|
}
|
|
return fallback;
|
|
}
|