Handling Errors
Let's see how error handling is done in RxJS.
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):
Press + to interact
.subscribe(function next(val) { /* A new value has arrived */ },function error(err) { /* An error occured */ },function done() { /* The observable is done */ });
next
function
The first is known as the next
function (that you’ve been using ...
Access this course and 1400+ top-rated courses and projects.