简体   繁体   中英

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. 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?

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;
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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