我们正在开发一个React应用,该应用使用Axios进行REST API调用。而且,我们随机看到请求超时。我们检查了网络连接,情况很好(100 MBPS连接)。我们检查了服务器日志,请求到达了服务器,并且请求已得到处理,没有任何错误。但是客户从未得到回应。我在下面添加了用于进行这些api调用的代码。如果您发现代码有任何问题,将不胜感激。如果您认为代码看起来不错,请向我们提供一些解决/调试超时的提示。我还在下面添加了错误。
import axios from 'axios';
import axiosRetry from 'axios-retry';
import { v4 } from 'uuid';
axios.defaults.timeout = 30000;
axios.interceptors.request.use((config) => {
const updatedConfig = { ...config };
updatedConfig.headers['X-CORRELATION-ID'] = v4();
return updatedConfig;
});
axiosRetry(axios, {
retries: 3,
retryDelay: (retryCount) => retryCount * 1000,
});
axios({
method: 'get',
url: `${requestURL}`,
headers: {
authorization: `Bearer ${token}`,
},
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
{
"error": {
"message": "timeout of 30000ms exceeded",
"name": "Error",
"stack": "Error: timeout of 30000ms exceeded\n at e.exports (https://file.js:2:2141051)\n at XMLHttpRequest.h.ontimeout (https://file.js:2:2140157)",
"config": {
"url": "requestURL",
"method": "get",
"headers": {
"Accept": "application/json, text/plain, */*",
"authorization": "Bearer TOKEN",
"X-CORRELATION-ID": "UDID"
},
"transformRequest": [null],
"transformResponse": [null],
"timeout": 30000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"axios-retry": {
"retryCount": 0,
"lastRequestTime": 1597096169071
}
},
"code": "ECONNABORTED"
}
}
预先感谢