5 lessons

Error Models

A stable error contract: machine-readable codes, a taxonomy clients can branch on, field-level validation feedback, explicit retryability, and honest partial-failure semantics.

RequirementConsumersResource ModelStyleContractValidationAuthorizationErrorsIdempotencyPaginationVersioningObservabilityEvolutionTrade-offs

Every lesson below names the consumers, the design question and the guarantee before recommending anything. Recommendations come with what they cost, when not to use them, and how they evolve.

The Error Model: Structure Over Apology

A failing response is still a response, and clients write code against it. A stable error model — machine-readable code, human message, request id, structured details — is a contract clause, not a courtesy.

Q · When this API fails, what exactly does the client learn, and what can its code do about it?
An Error Taxonomy Clients Can Branch On

Validation, authentication, authorization, not-found, conflict, rate-limit, dependency, internal: eight categories with different owners, different fixes and different retry rules. Collapse them and every client guesses; distinguish them and clients can be correct.

Q · Which distinct kinds of failure can this API produce, and does the contract let a client tell them apart mechanically?
Validation Errors: Feedback, Not Verdicts

Reject invalid input at the boundary, and say exactly which field failed which rule — all of them, in one pass. A validation error is a collaboration with the caller; "bad request" is a verdict nobody can act on.

Q · When a request fails validation, does the response let the caller fix every problem in one round trip — mechanically?
Retryability: Telling Clients What To Do Next

Every error answers a question the client is definitely asking: do I try again? A contract that states retryability explicitly — status semantics, Retry-After, a retryable flag — replaces a thousand guessed retry loops with one correct one.

Q · For every failure this API can produce, does the contract say whether, when and how the client should retry?
Partial Failure: When 3 of 5 Succeed

A batch request where some items succeed and some fail has no honest single status code. The contract must choose — atomic, best-effort with a per-item report, or a mix — and say so before the first consumer assumes the wrong one.

Q · When one request carries many operations and only some succeed, what does the response claim — and what is the caller supposed to do next?