2 min read
Switch on code
Maintain a small map from code to user copy.
const COPY = {
consent_required: 'Please tick the consent box to continue.',
invalid_email: 'That email address doesn’t look right.',
rate_limited: 'You’re going a bit fast — try again in a moment.',
};
showUser(COPY[code] || 'Something went wrong. Please try again.');
Keep raw detail internal
Log status, code, param and message for yourself; the user gets your curated copy. The envelope is for you, not them.
Guide the fix
When param is present, highlight that field in your form so the user knows exactly what to correct.
Frequently asked questions
Why not surface error.message directly?
It targets developers and may be reworded. Map the stable code to your own tone-appropriate copy so wording changes never leak to users.
What about unknown codes?
Fall back to a generic message plus the retry class from the HTTP status. Log the unknown code so you can add copy for it later.
Funding for UK limited companies
Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.