这是我的代码:

this._api.getCompanies().subscribe(
    res => this.companies = JSON.parse(res),
    exception => {if(this._api.responseErrorProcess(exception)) { // in case this retured TRUE then I need to retry() } }
)

万一发生异常,它将被发送到API中的函数,如果问题已解决(例如刷新 token ),则返回true,并且只需要在解决该问题后重试

我不知道如何重试。

最佳答案

.getCompanies()之后的.map调用中,添加 .retryWhen :

.retryWhen((errors) => {
    return errors.scan((errorCount, err) => errorCount + 1, 0)
                 .takeWhile((errorCount) => errorCount < 2);
});

在此示例中,可观察对象在2次失败后完成(errorCount < 2)。

关于angular2/RxJS-如何从内部Subscribe()重试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40175255/

10-11 12:55