Angular:需要使用重试和HTTPCLIENT管理错误

发布于 2025-01-29 08:52:59 字数 643 浏览 5 评论 0原文

当我试图在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文