Handling Errors
Understand how RxJS observables manage errors during asynchronous event streams. Learn to handle errors in the subscribe method with next, error, and done functions, and use throwError to manually trigger errors. This lesson helps you implement effective error handling to make your reactive applications more robust.
As powerful as observables are, they can’t prevent errors from happening. Instead, they provide a concrete way to gracefully handle errors as they arise.
Error handling in subscribe
Errors are handled in the subscribe call (same as regular data).
So far, the examples have only passed a single parameter to .subscribe—a function that runs for every datum that arrives at the end of the stream.
Turns out, a total of three parameters can be passed in (the latter two being optional):
next function
The first is known as the next function (that you’ve been using until this point).
It’s called on every new value passed down the observable. This is the option you’ve been using so far.
error function
The second, error