What HTTP Status code to use when a dependency/downstream (like a 3rd party API) fails?

前端 未结 1 1159
独厮守ぢ
独厮守ぢ 2021-01-19 07:54

We have a route in our API which (when called) hits another 3rd party API.

e.g.

HTTP-GET /account/1

this returns some data from our data

相关标签:
1条回答
  • 2021-01-19 08:35

    Now, if this 3rd party api call fails for any reason (fails == 4**, 5** or even a 200 OK but the content is some error message) then what error status code should I pass back to the client calling my API?

    APIs should be designed from the consumer's perspective. In most of situations, the API consumer wont't care if the request is fulfilled by the server they are firing a request to or by a downstream server.

    If the request to the downstream server prevents your server from fulfilling the client request, you could go for 500 or 503. Alternatively you could return some cached data (if you have any) and return a 2xx status code.

    0 讨论(0)
提交回复
热议问题