简体   繁体   English

如何仅对RxJ中源observable发出的某些错误进行重试

[英]How to retry only on certain error emitted by the source observable in RxJs

A srcObservable.retry() will catch the error emitted by the srcObservable and resubscribe to the srcObservable regardless of the type of the error. 无论错误的类型如何,srcObservable.retry()都将捕获srcObservable发出的错误并重新订阅srcObservable。 However, on certain scenario, it is wanted to only retry on certain type of error emitted by the srcObservable. 但是,在某些情况下,只希望重试srcObservable发出的某种类型的错误。 Is there a way to do so in RxJs neatly? 有没有办法在RxJs中整齐地这样做?

Try using retryWhen : 尝试使用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;
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM