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

為{幸葍}努か 提交于 2019-12-11 02:03:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!