O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Acting when an error occurs

When an error occurs, the observable stops sending new data. We can use different strategies, such as switching to another observable or retry, but these are more advanced so first we will see how an observer can be notified by an error. As you probably remember, the subscribe() method from the observable object lets you pass up to three functions or allows an observer to be notified when an error occurs.

Take a look at the following signature:

observable.subscribe([onNext], [onError], [onCompleted]); 

The parameters are optional:

  • onNext: This function is to be called when new data is available in this observable. The function receives the data itself as a parameter.
  • onError: This function is to be called when ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required