Reading an Error Response
The first time a request comes back wrong, it feels like the conversation broke. It did not. An error is the conversation: the server received your request, read it, considered it, and answered — with a status, with headers, and usually with a sentence naming the exact thing to change. The only real failure available here is not reading the answer.
Think of a parcel returned to your letterbox with a sticker on it: "addressee unknown", or "postage due", and a tracking number printed underneath. The sticker is not the postal service being rude. It is the postal service being specific — it tells you which of your assumptions was wrong, and gives you a number to quote if you need to ask about this exact parcel. An API error is that sticker, and this page teaches you to read one.
An Error Has the Same Anatomy
Nothing new arrives with an error. It is a response, built from the same three parts Chapter 2 took apart: a status line with the three digits, a set of headers, and a body. The status line gives the family — the problem is on your side, or on theirs. The headers describe the body. And the body is where an API puts its story.
Here is one, in full. Vera asked for a page of stations and typed the word "nine" where a number belonged. Tandem read the request, understood it, and declined it — the status is 422, and the body names the parameter that was wrong and what it should have been.
HTTP/1.1 422 Unprocessable Content
Content-Type: application/json
{"error": {"code": "invalid_parameter",
"message": "limit must be an integer",
"request_id": "req_9f2c"}}
Read that body aloud and the repair is already done: the limit has to be a whole number, so send 50 instead of a word. Beginners tend to see a wall of punctuation and look away at exactly the moment the answer is on the screen. Slowing down for the six seconds it takes to read the sentence is, honestly, the largest single improvement available on this page.
The Three Fields That Matter
Most error bodies carry three useful things, and each has a different audience. The code is a short label — invalid_parameter — that stays the same across releases and appears in the endpoint's error list in the documentation. It is meant for programs, so it never changes its wording to sound friendlier.
The message is written for a person. It is the sentence beginners skip and professionals read first, because it usually names the field, the expected type, or the missing header. Its wording can change between releases, which is exactly why the stable label sits beside it.
The request_id — req_9f2c in the example above — is your claim ticket. Tandem writes a line in its own logs for every request it handles, tagged with that id. Quote it to Jonas and he can look up this one request, out of millions, and see what his side saw. Without it, a support conversation becomes archaeology: two people guessing at which of yesterday's requests you meant.
Error Shapes Vary, the Idea Does Not
Not every API wraps its error in a field called error. Some put the three fields at the top level. Some name them type, detail, and trace_id. A few still answer with a line of plain text and nothing else — Chapter 4 already warned you that not everything is JSON, and errors are where that shows up most.
The costume changes; the reading strategy does not. Find the status. Find the machine label, if there is one. Find the human sentence. Find the identifier. If a piece is missing, note that it is missing and move on with what you have — the status line alone still tells you whose side the problem is on, which is the next two pages of this book.
The Error List Is Documentation
Chapter 6 walked you through the five bands of a reference page, and the last one was the error list: every way this endpoint can say no, each with its status and its label. That list is not a warning notice. It is the API telling you in advance the complete set of refusals it is capable of, which means every error you are ever going to meet on that endpoint has already been printed and explained.
Reading it before you integrate is how people look prescient. When the 403 arrives, they do not investigate — they recognize it, because they read the line about scopes three days ago. That is the whole trick, and it costs about two minutes per endpoint.
- "An error means I broke something." It means the server declined and said why. Nothing is damaged, no data was harmed, and the message is usually the repair manual for the thing that was declined.
- "The error body is technical noise to scroll past." It is the most information-dense text in the whole exchange. The message field frequently contains the literal fix, spelled out, in a language you read fluently.
- "request_id is internal junk for the provider." It is your claim ticket, and every escalation later in this chapter leads with it. A support request without one asks the provider to search a haystack for a needle you could have handed them.
- "The three digits tell me everything I need." They tell you the family and whose side the problem is on, which is a lot. They do not tell you which parameter was wrong. That sentence lives in the body.
- Reading errors calmly is the emotional core of API confidence. The difference between someone who is nervous around APIs and someone who is not is mostly this one habit.
- Code, message, id is a triage that works on every API you will ever touch, including all the real ones waiting in the last chapter. Learn it once here, on Tandem, and it transfers whole.
Knowledge Check
What is an error response, structurally?
- A broken exchange that ended before the server could reply properly
- A normal response, built from the same three parts as any other
- Your original request sent back to you with a note attached
- A signal that the server crashed while handling your request
The body contains "code": "invalid_parameter" and a message. Who is the code for?
- People, since it is shorter and easier to read than the message
- Programs, because it is a stable label that does not get reworded
- Support staff, who use it to find your exact request in the logs
- Billing systems, which count refusals separately from successes
Why does the error body carry a request_id?
- So you can retry the same request without building it again from scratch
- So the server can put your requests back into the order you sent them
- So the provider can locate this exact request inside their own logs
- So the provider can confirm the request really came from your key
An API answers a failed request with one line of plain text and no JSON at all. What now?
- Treat the response as malformed, since errors are always sent as JSON
- Read the status line and the text, and work with what is there
- Send the request again and hope a fuller error body comes back
- Ask for JSON by adding a header, since every API can produce it
You got correct