Intercepting HTTP Calls
Explore how to build HTTP interceptors in Angular to manage failed AJAX requests by retrying intelligently and displaying errors cleanly. Understand how to use RxJS operators like retryWhen and tap to handle HTTP call flows, ensuring robust communication and better user feedback.
We'll cover the following...
Interceptors
In addition to return types and JSON parsing, HttpClient introduces interceptors, which is a tool that exposes any AJAX request made in the application for modification.
Let’s add two of these:
-
One, a conditional retry service, attempts to intelligently rerun failed HTTP requests behind the scenes before the user sees an error state and manually retries.
-
The other listens in to every request and on an unreconcilable error, cleanly displays an error message (as opposed to a flow-breaking
alertor a silent failure).
The first step to building an interceptor is to generate a service to hold that structure.
Generate ...