Files
multica/apps/mobile/lib/auth-error.ts
Naiyuan Qing c09a096c2d fix(mobile): friendlier auth error messages on login + verify
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>
2026-05-21 18:51:55 +08:00

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;
}