Member-only story
Full NestJS Starter Kit — Part 6 Exception Handling
In this series of articles we’re walking through how to create a NestJS starter kit to use for your cloud applications. In our previous article we walked through how to setup API documentation and the generation of client source code.
In this article, we’ll be configuring our starter kit for exception handling. This will allow us to provide robust error scenarios and clearly communicate to our clients when errors happen!
Http Status Code Usage
Before we begin, it’s worth going over how we think about HTTP Status codes. HTTP status codes are an important part of the RESTful specification. They provide a more concise way of communicating what went wrong as part of an HTTP request. This can be used by clients to perform specific actions. For example, an HTTP status code in the 4XX range signifies a client error, aka the caller of the API did something wrong. This generally means that if the same request is tried again, they will receive the same error. A 5XX error, on the other hand, signifies something went wrong on the server side. For example, if there is a network blip between the API and the database, the API might return a 503 (Service Unavailable). It may be reasonable for the client to try making that request again, as the issue could be an intermittent issue that could be resolved.