这是我的代码:
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中的函数,然后如果问题得到修复则返回true(例如,令牌刷新),并且只需要在修复后再次重试
我无法弄清楚如何让它重试.
解决方法
在你的.getCompanies()调用之后.map添加一个
.retryWhen
:
.retryWhen((errors) => { return errors.scan((errorCount,err) => errorCount + 1,0) .takeWhile((errorCount) => errorCount < 2); });
在此示例中,observable在2次失败后完成(errorCount< 2).