Search code examples
restwebapihttp-status-codes

HTTP Status code for partial success or partial error response


I have an application where we send a request to two applications parallelly. Once I receive both the responses, I consolidate them to form a final response. When one of the systems fails to send a successful response, what should be the overall HTTP status code as it is a partial response?

I tried to use a common HTTP status code (like 503 service unavailable) incase of partial response. I'm new to web API standards and I'm not sure if this is the right approach.


Solution

  • From the perspective of the client calling your service, there's only 2 broad responses you can return: Success and failure. There is no 'partial failure'.

    So if one of the upstream requests fails, I would decide the response code this way:

    • Is the 'partial failure' a failure for the application? Return a 500/502/503 and optionally return information about the failure in the body (you can use this to indicate what partially succeeded).
    • Is it somewhat expected for the upstream service to fail and it doesn't matter for your client... then it's probably just 200 OK.

    Ultimately distinct HTTP status codes exist to allow clients to make a decision on 'what to do next'. A 5xx error clearly indicates there was an issue and potentially requires a developer's attention. So another way to think about this is... what do you want the client to do in case one of the upstream services failed?

    ideally servers never partially process a HTTP request, but I realize this is not always easy.