Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch the successful request using httpClient interceptor?

The most of the httpClient interceptor tutorials are catching the errors response in order to show an alert.

Examples:

https://ionicacademy.com/ionic-http-interceptor/

https://medium.com/@deniscangemi/intercept-http-requests-in-angular-c6392b7b0e0

It possible to present a loader for each HTTP request using the interceptor?

If yes, How to handle or catch the successful HTTP request in order to dismiss the loader.

like image 787
Khaled Ramadan Avatar asked Oct 20 '25 12:10

Khaled Ramadan


1 Answers

You can add a tap function inside the pipe as well, which will execute for every run, like so:

            import { tap, catchError } from 'rxjs/operators';

            // ...

            return next.handle(clonedReq).pipe(
                tap(data => {
                  // Do your success stuff in here
                }),
                catchError(error => {
                  // Do your error handling in here
                })
            );
like image 102
user184994 Avatar answered Oct 22 '25 03:10

user184994