I'm writing a service that returns data about another request to the consumer (for example, retrieving the un-shortened URL from a bitly or t.co address). In most situations, I can return a status code to mirror the code I received from the server, but what status code is most appropriate when my service is unable to connect to the requested URL (if it doesn't exist, for example)? I was thinking 400 Bad Request
or 408 Request Timeout
, but is there a best practice here?
Status codes 309 through 399 are currently unassigned.
We tend to get -1 status codes when there are network issues or connection problems, so we display the user a network problems page in those cases.
A 200-level response means that everything is working exactly as it should. 200: “Everything is OK.” This is the code that is delivered when a web page or resource acts exactly the way it's expected to. 201: “Created.” The server has fulfilled the browser's request, and as a result, has created a new resource.
HTTP response codes 200 – 299 are bearers of good news: the request has been accepted, a new request has been created, or a certain problem was solved.
503 Service Unavailable
seems like an appropriate choice. The 4xx
codes are meant to indicate the client did something wrong. In the case you specify, it's a service error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With