Angular:需要使用重试和HTTPCLIENT管理错误
当我试图在httpclient.post进行了几次重试后尝试捕获最后一个错误时,我会有问题。重试和延迟工作正常,但是我最终(在最后一次重试失败之后)我最终会遇到ManageError功能。感谢您的帮助
this.httpClient.post<any>(url, payload)
.pipe(
retryWhen((error) => {
return error.pipe(delay(TIMER_BETWEEN_REQUESTS), take(NUMBER_OF_RETRY),
catchError(err=>throwError(() => "getUnidentifiedBag has failed " + NUMBER_OF_RETRY + " times: " + err)))}
)
)
.subscribe({ next: (response) => {
console.log("response = ", JSON.stringify(response));
}, error: (err) => {
this.manageError(JSON.stringify(err), SEARCH_ERROR_MESSAGE);
}
});
I have an issue when I try to catch the last error after a few retries of a HttpClient.post. The retries and delay work fine, but I would like at the end (after the last retry has failed) that I end up in my manageError function. Thanks for your help
this.httpClient.post<any>(url, payload)
.pipe(
retryWhen((error) => {
return error.pipe(delay(TIMER_BETWEEN_REQUESTS), take(NUMBER_OF_RETRY),
catchError(err=>throwError(() => "getUnidentifiedBag has failed " + NUMBER_OF_RETRY + " times: " + err)))}
)
)
.subscribe({ next: (response) => {
console.log("response = ", JSON.stringify(response));
}, error: (err) => {
this.manageError(JSON.stringify(err), SEARCH_ERROR_MESSAGE);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论