HTTP status code for a partial successful request
I've had the same problem, and I've ended up using two different solutions:
- HTTP return code
202: Accepted
, indicating that the request was ok, but there's no guarantee everything actually went as it should. - Return a normal
200
in the response, but include a list of what didn't pan out in the response body.
The second one usually works best, but the first one is great if you're lazy or use a queue for processing.
I needed the same issue and after reading a bit of the documentation, the best solution to this problem seems to respond with an non-standard 2xx response. A generic client will treat this as success but a specific client can understand what has happened. You may also support this with custom headers in form X-failed: thispart code. You probably should include what is the problem with the operation as text so that generic clients will be able to display nature of what has happened. Here is what I have done where a file is uploaded but the processing cannot be done at this moment:
HTTP/1.1 210 Partial success
X-failed: processing
X-reason: server busy
File has been uploaded, however, the task associated with the
file has not started as the server is busy. Re-request processing
at a later time.
I've dealt with a very similar issue. In this case, I returned a
207 Multi-Status
Now, this isn't strict HTTP, it's part of the WebDAV extension, so if you don't have control over the client too, then this isn't good for you. If you do, you could do something like so:
<?xml version="1.0" encoding="utf-8" ?>
<D:multistatus xmlns:D='DAV:'>
<D:response>
<D:user>user-123</D:user>
<D:status>success</D:status>
</D:response>
<D:response>
<D:user>user-789</D:user>
<D:status>failure</D:status>
</D:response>
</D:multistatus>
But again, this is an HTTP extension, and you need to have control of the client as well.