Catch and continue

Sooner or later, we will have a stream that will throw an error. Let's see what that can look like:

// example of a stream with an errorlet stream$ = Rx.Observable.create(observer => {  observer.next(1);  observer.error('an error is thrown');    observer.next(2);});stream$.subscribe(  data => console.log(data), // 1   error => console.error(error) // 'error is thrown');

In the preceding code, we set up a scenario where we first emit a value, followed by emitting an error. The first value is captured in our first callback in our subscribe method. The second emitted thing, the error, is captured by our error callback. The third emitted value does not get emitted to our subscriber because our stream has been interrupted by the error. ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.