6. Handling errors

Error Handling

Throughout this course we've been working only with requests. And we did the requests correctly & got the right data (response). What if we made the wrong request or how do we know whether the response that came is right or wrong ?

When we make a wrong request, we will get an error code ( basically HTTP response status code). Chances are you faced one of the most popular status codes when you typed the wrong link — 404. 404 is one of the type of HTTP Status Code that tells about the state of response.

Like 404, there are multiple type of HTTP status code which

So, by understanding the status code you (or actually systems you implement) can immediately tell what’s happened to your request.

There are four groups of status codes. Within each group there are specific numbers that tell us more detail about the response but really knowing just the four general groups, is usually enough.

  • Status codes in the 200s tell us everything is okay. (i.e. we made the right request & got the correct response)
  • 300s status codes tell us that we've been redirected to the appropriate resource.
  • 400s status codes tell us that there was a problem on our end. (Something wrong with our request.)
    • Usually when working with APIs this means there's something wrong with our request URL.
  • And then, 500 status codes tell us that there's something wrong on the end of the server.

List of frequently used HTTP Status Codes

HTTP Status CodeDescription
204No Content
300Mutliple Choices
301Moved Permanently
304Not Modified
307Temporary Redirect
308Permanent Redirect
400Bad Request
402Payment Required
404Not Found
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
503Gateway Timeout

Here is a interesting way to know about Status code, https://http.cat/

Type the status code, you want to know about.