Axios GET请求超时随机

问题描述

我们正在开发一个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"
    }
}

预先感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...