Recipe

Read the error envelope

Every failure tells you exactly what went wrong — if you read the envelope. type gives the class, code the specific reason, message a human explanation, and param the offending field. This recipe turns the envelope into a decision.

2 min read

typeThe class
codeThe reason
paramThe field

Parse all four fields

Never act on the HTTP status alone.

const { type, code, message, param } = (await res.json()).error;
log.warn({ status: res.status, code, param, message });

Decide from type + code

Use type for the retry/no-retry split and code for the specific behaviour, per the envelope reference. Look up an unfamiliar code in the catalogue.

Surface the right thing

Show users a message derived from code (never the raw message, which may change), and point form errors at the field named in param.

Frequently asked questions

Why not just show error.message to users?

The message is for developers and may be reworded over time. Map the stable code to your own user-facing copy.

What if param is absent?

Then the error is not about one specific field (e.g. a rate limit or a server error). Only field-validation errors carry param.

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.