【问题标题】:axios-retry not working as expected. What is wrong with my config?axios-retry 未按预期工作。我的配置有什么问题?
【发布时间】:2022-08-21 03:30:30
【问题描述】:

我已经按照https://www.npmjs.com/package/axios-retry 在我的 nodejs 应用程序中配置了 axios-retry

以下是我的代码

import axios from \'axios\';
import axiosRetry from \'axios-retry\';


export class RetryRoute {

  public async testRetry(
    req: express.Request,
    res: express.Response,
    next: express.NextFunction,
 ): Promise<any> {
     const client = axios.create({ baseURL: `http://www.test.com/` });
     axiosRetry(axios, { retries: 3 });

     client.get(\'/error\') 
        .then(result => {
            this.logger.info(\'success\', result);
            result.data; 
        }).catch(error => { 
            console.log(\'error\', error.message);
            error !== undefined
        });
 }
}

console.log(\'error\', error.message);.按预期打印。这意味着调用失败,代码 404 符合预期。但是重试的下一个呼叫没有发生。

  • 你不应该使用axiosRetry(client, { retries: 3 }) 吗?

标签: node.js axios axios-retry


【解决方案1】:

您需要指定重试条件,下面的代码为每个失败的请求重试

 axiosRetry(axios, {
 retries: 3,
 retryCondition: () => true
 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-19
    • 2020-08-17
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    相关资源
    最近更新 更多