问题
A srcObservable.retry() will catch the error emitted by the srcObservable and resubscribe to the srcObservable regardless of the type of the error. However, on certain scenario, it is wanted to only retry on certain type of error emitted by the srcObservable. Is there a way to do so in RxJs neatly?
回答1:
Try using retryWhen:
src.retryWhen(function (errors) {
// retry for some errors, end the stream with an error for others
return errors.do(function (e) {
if (!canRetry(e)) {
throw e;
}
});
});
来源:https://stackoverflow.com/questions/29135235/how-to-retry-only-on-certain-error-emitted-by-the-source-observable-in-rxjs