codeis stable and snake_case: branch on it.messageis for people. It may change.detailsis there when the error has more to say, shaped per code.
Validation
422 validation_failed lists every problem at once in details.fields:
Status codes
Each endpoint lists the codes it can answer in the API reference.