Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading