【问题标题】:How to fix Cannot read property 'axios-retry' of undefined如何修复 Cannot read property \'axios-retry\' of undefined
【发布时间】:2022-11-30 18:48:58
【问题描述】:

我一直在 axios 和 axios retry 上遇到这个问题 错误

TypeError: Cannot read property 'axios-retry' of undefined
    at getCurrentState (index.js:118)
    at index.js:264
    at tryCallOne (core.js:37)
    at core.js:123
    at JSTimers.js:241
    at _callTimer (JSTimers.js:112)
    at _callImmediatesPass (JSTimers.js:166)
    at MessageQueue.callImmediates [as _immediatesCallback] (JSTimers.js:411)
    at MessageQueue.__callImmediates (MessageQueue.js:388)
    at MessageQueue.js:132

包.json

      "axios": "1.2.0",
       "axios-retry": "3.3.1",
axiosRetry(axios, {
    retries: 0,
    retryDelay: count => count * 1000,
    },
})
const fetchCall = (url, requestInfo) =>
    axios({
        method: requestInfo.method, 
        url, 
        timeout: requestInfo.timeout,
        headers: requestInfo.headers,
        data: requestInfo.body,
        'axios-retry': {
            retries:1
          },
    })

我尝试升级两个包 axios(0.18.1 -> 1.2.0) 和 axios(3.1.9 -> 3.3.1) 重试

【问题讨论】:

    标签: javascript react-native axios axios-retry


    【解决方案1】:

    我不确定你是否可以动态添加重试。而是像以前一样尝试创建一个客户端并使用配置,就像这样:

    import axios from 'axios'
    import axiosRetry from 'axios-retry'
    
    const axiosClient = axios.create()
    
    axiosRetry(axiosClient, {
        retries: 0,
        retryDelay: count => count * 1000,
      },
    })
    
    export default axiosClient
    

    然后只使用这个客户端的所有东西,而不是直接从包中导入的那个

    【讨论】:

      猜你喜欢
      • 2020-08-12
      • 2020-05-02
      • 1970-01-01
      • 2021-10-31
      • 2021-06-25
      • 2020-01-21
      • 2020-10-25
      • 2022-10-18
      • 2017-04-24
      相关资源
      最近更新 更多