skip to content

throwError

 

throwError creates an Observable, that will immediately emit an error
In the example below a value on timer will be substituted with a throwError stream at 10ms:

1
2
3
4
5
6
7
8
9
10
11
12
const { rxObserver } = require('api/v0.3');
const { timer, throwError } = require('rxjs');
const { switchMap } = require('rxjs/operators');

timer(10).pipe(
    switchMap(()=>
      throwError('Err!')
    )
  )
  .subscribe(rxObserver());

0msstartErr!!

Check out "Error handling in RxJS" article to get better understanding how not to fail with Observables.