Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 database AND from .. say .. a 3rd party api like Auth0/Okta/SalesForce/whatever.

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?

Initially I was thinking an HTTP-500-Server-Error but ... I'm not so sure now because I can prevent this error from occurring in the server if I return a nice error message back to the client. So then I thought, return an HTTP-200-OK which contains some key/value of the downstream issue/error ... but is this really OK (pun intended). To me, HTTP-200-OK is like the answer returned is really ok.

So i'm not sure what people do in this scenario.

I feel like an HTTP-500 is for errors that occur but haven't really been handled and/or accounted for.

like image 250
Pure.Krome Avatar asked Sep 29 '18 08:09

Pure.Krome


People also ask

What is the status code when API is down?

The 204 status code is usually sent out in response to a PUT , POST , or DELETE request when the REST API declines to send back any status message or representation in the response message's body.

What does a 444 error mean?

A 444 No Response error indicates that the server has closed the connection with no returned information from a client request.

What is status code 201 in API?

The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.

What is a 412 error?

The HyperText Transfer Protocol (HTTP) 412 Precondition Failed client error response code indicates that access to the target resource has been denied.


1 Answers

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.

like image 141
cassiomolin Avatar answered Oct 06 '22 00:10

cassiomolin