The static Rx.Observable.catch() method present in Rxjs 4.x seems to be absent in RxJs 5.0.2
RxJS version:
5.0.2
Code to reproduce:
Rx.Observable.catch(
Rx.Observable.throw(new Error()),
Rx.Observable.of('only i will be emitted'),
Rx.Observable.of('never subscribed to')
)
.take(1)
.subscribe(
v => console.log(v),
err => console.log(err.message),
() => console.log('completed')
)
Expected behavior:
"only i will be emitted"
"completed"
Actual behavior:
"TypeError: Rx.Observable.catch is not a function"
I don't think this operator is needed, it's trivial to write.
Rx.Observable.of(
Rx.Observable.throw(new Error()),
Rx.Observable.of('only i will be emitted'),
Rx.Observable.of('never subscribed to')
).reduce((ob1, ob2) => ob1.catch(() => ob2), Rx.Observable.throw(''))
.mergeAll()
This was not 100% trivial for me to write. Learned something today though! :+1: So it seems that this issue can be resolved in one of the following ways:
1) Document absent catch() overload in MIGRATION.md + point to how to do this yourself?
2) Implement missing overload
Trivial to write, probably not trivial to come up with :)
More trivially than that, Observable.catch(a, b, c) is really just a.catch(() => b).catch(() => c):
Observable.throw(new Error())
.catch(() => Observable.of('only I will be emitted'))
.catch(() => Observable.of('never subscribed to'))
I hope that helps.
Closing as I believe it won't be added in core as it's achievable via existing opeartor chains.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
More trivially than that,
Observable.catch(a, b, c)is really justa.catch(() => b).catch(() => c):I hope that helps.