catchError lets you substitute an error on a stream with another stream
12345678910111213141516171819const { rxObserver } = require('api/v0.3'); const { timer, throwError, of } = require('rxjs'); const { switchMap, catchError } = require('rxjs/operators'); // emit an error in 5ms const error$ = timer(5).pipe( switchMap(() => throwError('oh')) ); const catch$ = error$.pipe( catchError(err => of(err)) ); error$.subscribe(rxObserver()); catch$.subscribe(rxObserver());
Check out "Error handling in RxJS" article to get better understanding how not to fail with Observables.