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 thisobservable
. The function receives the data itself as a parameter.onError
: This function is to be called when an error is propagated through thisobservable
. This function received theError
as a parameter.onCompleted
: This function is to be called when theobservable
is exhausted and all the data has already been propagated.
This method also has an overloaded implementation...