【发布时间】:2019-10-13 09:48:03
【问题描述】:
在角度方面,我是 httpClient 的新手,并尝试实施一种解决方案,以在 Internet 断开连接时重试 http 调用,即错误状态 = 0。当 3 次尝试失败时,我希望它抛出原始的 http 响应错误。
以下是我正在尝试的,但它不起作用。有什么想法吗?
return this.httpClient.post('https://server.com/logins', data, {headers: headers})
.pipe(retryWhen(errors => errors
.pipe(map((err, index) => {
// Caught Error, throw immediately
if (!err) {
throw err;
}
if (err.status !== 0) {
throw err;
}
// Disconnection error
if (index === 2) {
throw err;
}
return err;
}))
.pipe(delay(1000))))
【问题讨论】:
标签: angular rxjs httpclient