Best HTTP code for external subsystem failure

I am working on a system that provides a REST API. My system requires external API calls to complete some requests. These APIs sometimes fail (with internal server errors), and these failures prevent my system from successfully shutting down.

What is the best HTTP status code my system should return? I would like to distinguish failures of external systems from internal failures in my system, so I am not particularly pleased with the return of 500.

+5
source share
2 answers

In these cases, I prefer HTTP 502:

10.5.3 502 Bad Gateway

The server, acting as a gateway or proxy, received an incorrect response from the upstream server, which it accessed when trying to fulfill the request.

Although this is technically more suitable for proxies, I think it is closest to the fact that you can distinguish a server error (500) from an upstream server error.

+8
source

You can also consider returning HTTP 504 if the request timeout to the external system expires:

504 Gateway Timeout
The server acted as a gateway or proxy server and did not receive a timely response from the upstream server.

+1
source

Source: https://habr.com/ru/post/1233313/


All Articles