【问题标题】:unexpected behavior of apollo link retry on 400 error [closed]阿波罗链接重试400错误的意外行为[关闭]
【发布时间】:2020-06-12 14:11:42
【问题描述】:

description: Attempt an operation multiple times if it fails due to network or server errors.

我使用 apollo-link-retry 来重试发生服务器错误(5xx)时的调用。 但是当发生 400 错误(错误请求)时,它会重试,预计只会在服务器错误中重试。 网络错误是否意味着所有客户端错误(4xx)和服务器错误(5xx)? 如何停止重试 5xx 以外的错误?

【问题讨论】:

  • 问题清楚了,请重新打开。

标签: apollo apollo-client vue-apollo


【解决方案1】:

在 Apollo Client 的上下文中,有两种类型的错误 - GraphQL 错误(在响应中的 errors 数组中返回的错误)和网络错误。任何返回状态不是 200 的请求都被认为遇到了网络错误。默认的 RetryLink 配置没有那么精细——它只关心是否发生了网络错误,而不关心发生了什么样的错误。如果您希望重试某些错误,请为attempts 配置提供retryIf 函数,如docs 所示:

  attempts: {
    retryIf: (error, _operation) => {
      // return true or false depending on the properties on error
    }
  }
})

【讨论】:

  • 你的意思是说除了2xx之外的所有状态码都被认为是网络错误?
  • 我猜技术上是any status 300 or above
猜你喜欢
  • 2021-06-08
  • 2017-11-20
  • 2019-08-13
  • 2021-09-17
  • 2020-12-26
  • 1970-01-01
  • 2019-04-02
  • 2017-03-23
  • 2018-12-06
相关资源
最近更新 更多