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 ...