Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: noResponseRetries > 0 not retried #192

Open
SJrX opened this issue May 18, 2022 · 0 comments
Open

BUG: noResponseRetries > 0 not retried #192

SJrX opened this issue May 18, 2022 · 0 comments

Comments

@SJrX
Copy link

SJrX commented May 18, 2022

Hello,

We wanted to use this project for to retry random ECONNRESET errors however we noticed that they didn't get retried at all. There were a couple issues (including another broken interceptor), but there was still a bug in this project.

// If there's no config, or retries are disabled, return.
  if (!config || config.retry === 0) {
    return false;
  }

If you are only retrying noResponseRetries we always return false.

I changed the logic to this, but it still has another bug that I didn't want to fix (which is that we should have distinct retry counters for the noResponseRetries and retry.

/**
 * Determine based on config if we should retry the request.
 * @param err The AxiosError passed to the interceptor.
 */
export function shouldRetryRequest(err: AxiosError) {
  const config = (err.config as RaxConfig).raxConfig

  // If there's no config, or retries are disabled, return.
  if (!config) {
    return false
  }

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

  let retryLimit = 0
  if (err.response) {
    // This error has a response

    // If this wasn't in the list of status codes where we want
    // to automatically retry, return.
    if (err.response.status) {
      let isInRange = false
      for (const [min, max] of config.statusCodesToRetry!) {
        const status = err.response.status
        if (status >= min && status <= max) {
          isInRange = true
          break
        }
      }
      if (!isInRange) {
        return false
      }
    }
    retryLimit = config.retry || 0
  } else {
    retryLimit = config.noResponseRetries || 0
  }

  // If we are out of retry attempts, return
  return config.currentRetryAttempt < retryLimit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant