Error handling is a very big topic. It is an area that is easy to underestimate. Normally, when coding, we could be led to believe we just need to do certain things, such as ensure we don't have syntax errors or runtime errors. With streams, we mostly think of runtime errors. The question is, how should we act when an error occurs? Should we pretend like it rains and just throw the error away? Should we hope for a different outcome if we try the same code some time in the future, or should we maybe just give up when a certain type of error exists? Let's try to collect our thoughts and look at the different error approaches that exist within RxJS.
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 error
let stream$ = Rx.Observable.create(observer => {
observer.next(1);
observer.error('an error is thrown');
observer.next(2);
});
stream$.subscribe(
data => console.log...