4 ms·
Ah, the eternal battle. Do you return an HTTP error code if the problem lies in the domain? I think I've seen everything on that scale. On one end: { status:
by knallfrosch 3y ago
Ah, the eternal battle. Do you return an HTTP error code if the problem lies in the domain?
I think I've seen everything on that scale.
On one end:
{ status: 200, error: InsufficientFunds }
On the other:
- "let's use 409, it perfectly fits our use case"
+ "but we don't have useful error codes for all the other domain errors."
- alganet 3y agoStatus 200 with "InsufficientFunds" can be correct. Let's assume your resource is "/account/1234/withdraw-availability" It's a hypothetical endpoint you can GET to know if you can withdraw money. You hit it, and the request is sucessful (the server understood and will inform you whether withdrawaw is available or not). Let's assume your resource is "/account/1234/withdraw" This other hypothetical endpoint you can POST a request for money withdraw. Returning 200 here means the server understood and processed your request, so a 200 that does not withdraw makes no sense. The same endpoint could also return a success "201" accepted (the server understood the request, but it is not processed yet). In the body, there would be a link for "/withdrawaws/48957987593845983475/status", a resource specific to this future processing, which you can GET later (maybe 1ms later, within the same socket). This GET could also return a 200, saying that such withdrawaw was not possible (the server sucessfully understood the request and will inform you about the status of the withdrawaw). For this modeling stuff, the Roy Fielding dissertation about REST is more enlightening than the spec. The spec is still needed though.
- lstamour 3y agoOne more example, if your request contains a batch of operations, you generally have to return 200, or maybe 204, if it was successfully received and should not be retried in full. In the response body, you might give other response codes for specific errors or failures to retry in a new request. So it can easily make sense to return 200 when there are e.g. partial failures and partial success and the request was properly formatted, authorized and acted upon.