question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception in function shouldRetryRequest() when checking HTTP methods to retry

See original GitHub issue

In function shouldRetryRequest there’s this block of code

    // Only retry with configured HttpMethods.
    if (!err.config.method ||
        config.httpMethodsToRetry.indexOf(err.config.method.toUpperCase()) < 0) {
        return false;
    }

that fails evaluating second condition, because httpMethodsToRetry is an object, not an array.

Below goes the output from dev console, when the breakpoint was set on the line given above ^^^:

config.httpMethodsToRetry
{0: "GET", 1: "HEAD", 2: "OPTIONS", 3: "DELETE", 4: "PUT"}

That looks different from what gets set in raxConfig

    const raxConfig = {
    ....
        
      // HTTP methods to automatically retry.  Defaults to:
      // ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT']
      httpMethodsToRetry: ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT'],
    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
mpywcommented, Feb 15, 2019

@JustinBeckwith

v0.19.0-beta.1. Please see my comment. Now options are completely whitelisted and it doesn’t accept raxConfig.

3reactions
chaitya1001commented, Apr 20, 2018

I am also getting error,

Here is my relevant code,

axios.defaults.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: 3,

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

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

  // The response status codes to retry.  Supports a double
  // array with a list of ranges.  Defaults to:
  // [[100, 199], [429, 429], [500, 599]]
  httpStatusCodesToRetry: [[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: axios,

  // 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}`);
  }
};
const id = rax.attach(axios);

And here is the error,

TypeError: config.httpMethodsToRetry.indexOf is not a function
    at shouldRetryRequest (/Users/chaityashah/FracTEL/skrum/node_modules/retry-axios/build/src/index.js:96:35)
    at onError (/Users/chaityashah/FracTEL/skrum/node_modules/retry-axios/build/src/index.js:58:10)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement retry mechanism into python requests library?
This snippet of code will make all HTTP requests from the same session retry for a total of 5 times, sleeping between retries...
Read more >
Best Practices for Retry - Denali Balser
A retry is a mechanism that monitors a request, and on the detection of failure ... To get more specific, HTTP methods that...
Read more >
Retry HTTP Request with Backoff Strategy - Akinjide Bankole
Retrying HTTP Requests when network fails due to poor connection or server timeouts.
Read more >
org.jclouds.http.HttpCommand java code examples - Tabnine
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.
Read more >
How To Retry HTTP Requests Using a Decorator in Python
Failed requests to a server can cause us all sorts of issues, but rather than just handle the exception and log it away,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found