apollo 的意外行为 link 出现 400 错误时重试
unexpected behavior of apollo link retry on 400 error
description: Attempt an operation multiple times if it fails due to network or server errors.
我已经使用 apollo-link-retry 在发生服务器错误 (5xx) 时重试调用。
但是,当发生 400 错误(错误请求)时,它会重试,预计只会在服务器错误中重试。
网络错误是否意味着所有客户端错误(4xx)和服务器错误(5xx)?
如何停止重试 5xx 以外的错误?
在 Apollo Client 的上下文中,有两种类型的错误——GraphQL 错误(在响应中 errors
数组内返回的错误)和网络错误。任何 returns 状态不是 200 的请求都被认为遇到了网络错误。默认的 RetryLink 配置不是那么精细——它只关心是否发生了网络错误,而不关心发生了什么类型的错误。如果您想 不 重试某些错误,请向 attempts
配置提供 retryIf
函数,如 docs:
attempts: {
retryIf: (error, _operation) => {
// return true or false depending on the properties on error
}
}
})
description: Attempt an operation multiple times if it fails due to network or server errors.
我已经使用 apollo-link-retry 在发生服务器错误 (5xx) 时重试调用。 但是,当发生 400 错误(错误请求)时,它会重试,预计只会在服务器错误中重试。 网络错误是否意味着所有客户端错误(4xx)和服务器错误(5xx)? 如何停止重试 5xx 以外的错误?
在 Apollo Client 的上下文中,有两种类型的错误——GraphQL 错误(在响应中 errors
数组内返回的错误)和网络错误。任何 returns 状态不是 200 的请求都被认为遇到了网络错误。默认的 RetryLink 配置不是那么精细——它只关心是否发生了网络错误,而不关心发生了什么类型的错误。如果您想 不 重试某些错误,请向 attempts
配置提供 retryIf
函数,如 docs:
attempts: {
retryIf: (error, _operation) => {
// return true or false depending on the properties on error
}
}
})