以下是用于重试令牌验证端点失败尝试的代码:
const axios = require('axios')
const rax = require('retry-axios')
try {
const axiosInstance = axios.create();
const myRaxConfig = {
instance: axiosInstance,
retry: 4,
statusCodesToRetry: [[100, 199], [401, 429, 429], [500, 501, 502, 504, 599]],
httpMethodsToRetry: ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT', 'POST'],
retryDelay: 100,
noResponseRetries: 4,
onRetryAttempt: (err) => {
const cfg = rax.getConfig(err)
console.log(`Retry attempt #${cfg.currentRetryAttempt}`);
}
}
axiosInstance.defaults.raxConfig = myRaxConfig
const interceptorId = rax.attach(axiosInstance);
//const interceptorId = rax.attach()
console.log("DOING THIS ONE +++++++++~~~~~~~~~~~~~~~~~~~~~~~")
const tokenResult = await axiosInstance.post(`${process.env.URL}/api/token/verify`,
{
token
},
)
}
catch (err) {
logger.error('encounter error in verify: ', err)
//logger.error('encounter error in verify: ')
return false
}
然而,错误日志显示默认配置被使用了,由于这是一个POST请求,没有尝试重试:
错误输出:
...
"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8","User-Agent":"axios/0.19.0","Content-Length":252},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,
"raxConfig":{"currentRetryAttempt":0,"retry":3,"retryDelay":100,"httpMethodsToRetry":["GET","HEAD","PUT","OPTIONS","DELETE"],"noResponseRetries":2,"statusCodesToRetry":[[100,199],[429,429],[500,599]]}}}
axios请求正在使用默认的retry-axios配置。
如何覆盖默认的raxConfig?