Juan
Juan

Reputation: 2084

How to handle errors but skip further processing within a stream?

In this scenario

this.http.call().pipe(
    catchError((error) => {
        doSomething();
    }),
    switchMap((data) => {
        doMoreThings();
    }),
);

It's possible to not execute the switchMap when the catchError block is executed?

Upvotes: 1

Views: 63

Answers (1)

martin
martin

Reputation: 96891

It depends on what Observable you return from catchError's callback.

If you return empty(). Then it won't trigger switchMap because empty() just completes and doesn't emit any next notifications.

You can also return throwError(...) that emits just an error notifications and no next's.

Upvotes: 1

Related Questions