Reputation: 774
I'm implementing CRUD operations on a REST resource. Service can perform update only when the resource is in state 'X' and I need to show an error if resource state is not 'X'. What error should I throw if resource is not in state 'X'? 400 or 405 or something else?
Upvotes: 0
Views: 64
Reputation: 57204
What error should I throw if resource is not in state 'X'?
Either
the method received in the request-line is known by the origin server but not supported by the target resource.
the request could not be completed due to a conflict with the current state of the target resource.
the server understood the request but refuses to authorize it
Status codes are meta-data in the transfer of documents over a network domain. It's a hint that we give to general purpose clients to help them interpret the rest of the information in the response.
A way of deciding which code to use is to compose the response body, and then consider which of the codes is a best fit.
In practice, there doesn't seem to be a lot of difference between these codes (405 is cacheable? shrug). So you might do well to consider it an operator concern; which of these codes is going to make life easier for somebody reading the access log?
Upvotes: 1