Does RxJS have a way to handle errors that were not caught by subscriber?

568 Views Asked by At

RxJS allows to subscribe to a source with onNext, onError, onComplete.

I am looking for a way to construct an observable which allow users to handle errors with onError, but if there is error that is unhandled, I can show globally growl (a notification from primeng library).

Is there a nice way to catch unhandled in subscription errors.

Update1: I have noticed that Angular2 has a central ErrorHandler (Module level). The question is to attach it to UI somehow. https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html

1

There are 1 best solutions below

3
On

If you do not subscribe to the error event it will bubble. You can wrap your stream with try..catch to catch these to prevent your application from crashing.

try {
  Rx.Observable.throw(new Error('not caught')).subscribe();  
}
catch(err) {
  console.log('caught', err);
}