A call to an external service fails. The single most useful piece of information is the status code, and reading it properly tells you immediately whether the problem is your request or their service, which is the fork everything else depends on.
What do the ranges mean?
- Four hundred range. Your request was wrong.
- Five hundred range. Their service failed.
- Three hundred range. A redirect your client may not be following.
- No response at all. Network, address or firewall.
That distinction determines whether you are looking at your code or waiting for somebody else, and people spend hours on the wrong side of it.
What are the specific ones worth knowing?
Unauthorised means your credentials were not accepted; forbidden means they were accepted and you lack permission. Those are different problems and the words are frequently confused. Not found may mean the address is wrong or that the specific record does not exist.
What should you read first?
The response body, which almost always explains the problem in words and which people ignore in favour of the status code. Most services return a message naming the field that was wrong.
Here is the exact request I sent, with the credential removed, and here is the complete response including the body. What is it telling me is wrong?
How do you find out what you actually sent?
By logging the full request rather than what you think you constructed. Headers, address, method and body, exactly as they went out. The difference between the intended and actual request is where a large share of these bugs live.
Trying the same call with a command line tool is the other quick separation, since it establishes whether the problem is your code or the request itself.
What are the common causes?
A missing content type header, credentials in the wrong place or format, a trailing slash that matters, sending a form where the service expects structured data, and an environment variable that is empty in one environment.
The last one is worth checking first when something works locally and not in deployment.
What about timeouts?
Worth setting explicitly, since the default is frequently far too long or absent. A call with no timeout can hang indefinitely, which produces an application that appears frozen rather than one that reports a failure.
What should the handling do?
Distinguish between retryable and permanent failures. A five hundred error or a timeout is worth retrying with a delay; a four hundred error will fail identically every time, and retrying it wastes quota and time.
What about their documentation?
Authoritative, and worth checking against anything generated. Models frequently describe an earlier version of an API, with parameters that have been renamed or removed, and the resulting code is plausible and wrong.
What about rate limits?
A common cause of calls that work in testing and fail in use. Services limit how many requests you may make in a period, and exceeding it produces a specific status code that people frequently treat as a general failure.
The correct response is to slow down rather than to retry immediately, since retrying a rate limit failure makes it worse. Most services return a header saying how long to wait, which is the value to use, and respecting it is the difference between a brief pause and having your access suspended.
What is the order?
Status code, response body, actual request sent, then their documentation. Working through those four in order resolves the great majority of API problems, usually at the second step.