A customer fills in your order form, presses the button and gets a red box: "Something went wrong." Which field? Is the order saved? Was the card charged? They don't know, so they try again, call you, or leave. Each of those costs you something: a lost order, a support call, or a double order you sort out by hand.
Behind most of those boxes is a system that knows two answers, "worked" and "didn't". The fix sits on the server, not in the design, and it's cheap when it's built in from the start.
Every error needs a name
When something fails, your system should say what failed, in a form the page can act on. Not just "error", but "email missing", "card declined", "already registered". Developers call that an error code.
With a name, the page can offer the next step. Four I've built into projects:
- Email already registered: the message sits under the email field, with a "Log in instead" link.
- Too many attempts: "Wait 30 seconds and try again", with a countdown.
- Session expired: back to the login, then straight back to the page they were on.
- No permission: who can grant it, with that person's email.
Fix: every error message answers two questions: what happened, and what to do now. "Your card was declined. Try another card or call your bank." is a message. "Payment error" is not.
Show the error where the problem is
When a form fails, the customer wants to see which field to fix. A line under each field ("Email address is missing") beats one popup listing everything, and it beats "Invalid input" by far.
Watch out: many forms clear themselves after an error. The customer typed their address, phone number and order notes, and now has to start again. Plenty won't. Whatever they typed stays in the form.
Success needs the same clarity: "Order saved. A confirmation is on its way to you@company.com." A customer who isn't sure it worked presses the button again.
What an error must never show
Some error pages show too much: file paths, database queries, internal account numbers. Your customer can't use any of it. Someone looking for a weak spot in your system can.
Two rules I keep:
- Technical detail goes into the server log, never onto the screen.
- "This doesn't exist" and "you can't see this" get the same answer, so nobody can find out which accounts or orders exist by trying numbers.
A reference number for every problem
A customer writes: "Your site didn't work yesterday." Without a reference, someone searches the logs by time and guesses, and that can take hours.
Fix: every request gets a reference number. It goes into the server log and shows with the error. The customer sends you "req_abc123", and your developer finds the exact failure in seconds.
For your developer
What I put in place before a form or checkout goes live:
- One error shape across the API:
error(readable message),code(stable, machine-readable),details.fieldsfor field-level problems,requestId. - Status codes from a small set: 400, 401, 403, 404, 409, 422, 429, and 5xx without internals.
- 404 for both "doesn't exist" and "not yours", so IDs can't be enumerated.
- Validation errors mapped field by field from the schema (zod, Joi, valibot), never one comma-joined string.
requestIdset in middleware, on every log line and in every error response.
A failed signup, in that shape:
{
"error": "This email is already registered.",
"code": "EMAIL_TAKEN",
"details": { "fields": { "email": "Already registered. Log in instead?" } },
"requestId": "req_abc123"
}Fill in your own order form with a mistake on purpose. If it says "Something went wrong", send this post to whoever built it, or book a call.