retry axios Невозможно прочитать свойство 'attach' из undefined - PullRequest
0 голосов
/ 25 апреля 2019

Я хочу повторить запросы HTTP, я использую библиотеку запросов Axios http.

Я пытаюсь использовать библиотеку retry-axios (https://github.com/JustinBeckwith/retry-axios), но я получаю следующую ошибку в моем блоке перехвата

Невозможно прочитать свойство 'attach' из неопределенного

import axios from "axios";
import rax from "retry-axios";

try {
     ...
     const interceptorId = rax.attach();
     const metrics = await axios(this.getMetrics(session._id, sessionRequest._id));

} catch(err) {
    console.log(err);
}

public getMetrics(sessionId: any, requestId: any) {

        const url = this.config.backendUrl + "/check/metrics";

        const options = {
            url,
            method: "get",
            headers: {
                "X-IDCHECK-SESSION-ID": sessionId,
            },
            data: {},
            raxConfig: {
                // Retry 3 times on requests that return a response (500, etc) before giving up.  Defaults to 3.
                retry: 3,

                // Retry twice on errors that don't return a response (ENOTFOUND, ETIMEDOUT, etc).
                noResponseRetries: 2,

                // Milliseconds to delay at first.  Defaults to 100.
                retryDelay: 100,

                // HTTP methods to automatically retry.  Defaults to:
                // ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT']
                httpMethodsToRetry: ["GET", "HEAD", "OPTIONS", "DELETE", "PUT"],

                // The response status codes to retry.  Supports a double
                // array with a list of ranges.  Defaults to:
                // [[100, 199], [429, 429], [500, 599]]
                statusCodesToRetry: [[100, 199], [429, 429], [500, 599]],

                // If you are using a non static instance of Axios you need
                // to pass that instance here (const ax = axios.create())
                // instance: ax,

                // You can detect when a retry is happening, and figure out how many
                // retry attempts have been made
                onRetryAttempt: (err) => {
                  const cfg = rax.getConfig(err);
                  console.log(`Retry attempt #${cfg.currentRetryAttempt}`);
                },
              },
        };

        return options;

    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...