wolfhoundjesse wolfhoundjesse - 17 days ago 7
Javascript Question

Is Error Considered an Emission from an Observable in RxJs?

Quick question: Will

.do()
fire off when there is an error? The docs say, "Perform a side effect for every emission on the source Observable, but return an Observable that is identical to the source." Is an error considered an emission, too?

return this.authHttp.get(url)
.delay(5000)
.map(this.extractData)
.do(() => console.log("I'm doing something"))
.share()
.catch(error => {
if (isDev) this.toastr.error("The panels could not be retrieved from the API.");
return this.handleEerror(error);
});

Answer

The .do() method can take an optional onError callback for handling errors:

observable
  .do(
    value => console.log("I'm doing something"),
    err   => console.error('I got an error', err.stack)
  )

...otherwise it will just pass through the pipeline.

Comments