问题
I would like to use the onErrorResumeNext
feature of RxJS, i.e. to continue to receive events even if an error is received (instead of terminating).
But I can see in the following doc that there is no correspondance in RxJS5: https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md.
Is there a workaround to use such feature? Thanks!
回答1:
I've been looking for that operator too! I came up with a solution for my needs that I hope will help yours. It's not the best solution most likely, but I hope it can help until a better solution can be found by some others on here, or until this operator is added back in 5.0 (hopefully!) :)
var Observable = Rx.Observable;
var source1 = Observable.create(function(observer){
observer.error();
});
var source2 = Observable.create(function(observer){
observer.next('Continuing on');
observer.complete();
});
var stream = source1.catch(function(data){
return source2;
});
stream.subscribe(function(data){
console.log(data);
});
JS Bin Example: https://jsbin.com/qadozoveta/edit?html,js,console
回答2:
You can use the following in rxjs5 still.
Observable.onErrorResumeNext(observable1$, observable2$, observable3$...)
.subscribe(() => { ... })
onErrorResumeNext source code
来源:https://stackoverflow.com/questions/35772998/how-to-resumeonerror-or-similar-in-rxjs5