Handling runtime errors
The most common runtime errors in an Angular application come from the interaction with an HTTP API. Entering the wrong login credentials or sending data in the wrong format can result in an HTTP error. An Angular application can handle HTTP errors in the following ways:
- Explicitly during the execution of a particular HTTP request
- Globally in the global error handler of the application
- Centrally using an HTTP interceptor
In the following section, we will explore how to handle an HTTP error in a specific HTTP request.
Catching HTTP request errors
Handling errors in HTTP requests typically requires manually inspecting the information returned in the error response object. RxJS provides the catchError
operator to simplify that. It can catch potential errors when initiating an HTTP request with the pipe
operator.
You will need the source code of the Angular application we created in Chapter 10, Collecting User...