Errors
Failures return a JSON object under an error key.
Types
Status codes
Codes
Branch on these. They are stable; new ones may be added.
Validation failures
A validation_failed error carries details, one entry per offending field. Show these against the fields they name rather than concatenating them into one message.
Unrecognised fields are rejected, not ignored
Send a field this API does not know and the request fails with the field named, rather than succeeding while quietly dropping your data. A typo in a field name is a loud error, which is the behaviour you want when the alternative is discovering months later that a column was never being saved.
One exception worth coding around
A 401 does not use the envelope above. It returns a plain-text reason. A client that assumes JSON on every error path will throw while handling the very case it was written for. Check the status before parsing, or guard the parse.
Every other status on this page returns the JSON error object.