API-17Recommended
Keep error types stable
Treat each error type as part of the contract. Clients branch on it, so never rename or reuse one.
How to do it
List every problem type in the OpenAPI file and on a public page at its URI. Change the wording of detail freely, but never the type. Clients branch on type, never on title or detail text. Map each typed domain exception to one error type.
How to check
A test lists the problem types the code can return. Each one appears in the contract and its URI answers 200.
Sources
Related rules
- ARC-27 Use typed domain exceptions in Clean code and architecture
- API-85 Give every GraphQL error a stable code in API design
- LOC-34 Give every error a code that clients can translate in Localization
- DEV-1 Exit with zero only when the command did everything it was asked in Developer tools, SDKs and CLIs
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/errors/stable-error-types">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.