How to use axios-retry - 10 common examples

To help you get started, we’ve selected a few axios-retry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chanzuckerberg / idseq-web / app / assets / src / api / index.js View on Github external
const uploadFileToUrlWithRetries = async (
  file,
  url,
  { onUploadProgress, onSuccess, onError }
) => {
  const config = {
    onUploadProgress,
  };

  // Retry up to 5 times with a 30s delay. axiosRetry interceptor means that 'catch' won't be
  // called until all tries fail.
  const client = axios.create();
  axiosRetry(client, {
    retries: 5,
    retryDelay: () => 30000,
    retryCondition: () => true,
  });

  return client
    .put(url, file, config)
    .then(onSuccess)
    .catch(onError);
};
github kndt84 / aws-api-gateway-client / src / lib / apiGatewayCore / sigV4Client.js View on Github external
signedRequest.baseURL = url;
      let client = axios.create(signedRequest);

      // Allow user configurable delay, or built-in exponential delay
      let retryDelay = function() {
 return 0;
};
      if (config.retryDelay === 'exponential') {
        retryDelay = axiosRetry.exponentialDelay;
      } else if (typeof config.retryDelay === 'number') {
        retryDelay = () => parseInt(config.retryDelay);
      } else if (typeof config.retryDelay === 'function') {
        retryDelay = config.retryDelay;
      }

      axiosRetry(client, {
        retries: config.retries,
        retryCondition: config.retryCondition,
        retryDelay,
      });
      return client.request({method: verb});
    }
    signedRequest.method = verb;
    signedRequest.url = url;
    return axios(signedRequest);
  };
github nicschumann / arena-connectome / src / arena-api / index.js View on Github external
var arena = function( config ) {

    var client = axios.create({
        responseType: 'json',
        baseURL: config.arena_api,
    //    params: { noCache: true },
    });

    axiosRetry( client, { retries: 3 });

    function makeRequest( root, slug, action ) {

        return client.get( path.join( root, slug, action ) );

    }

    return {
        channel: function( slug, action ) {

            return makeRequest( 'channels', slug || '', action || '');

        },

        block: function( slug, action ) {
github neiker / analytics-react-native / src / index.js View on Github external
import base64 from 'base-64';

// eslint-disable-next-line import/no-unresolved
import { Platform } from 'react-native';

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

import assert from './helpers/assert';
import validate from './helpers/validate';
import uid from './helpers/uid';

axiosRetry(axios, { retries: 3 });

const VERSION = require('../package.json').version;

const noop = () => {};

/**
 * Expose an `Analytics` client.
 */
export default class Analytics {
  /**
   * Initialize a new `Analytics` with your Segment project's `writeKey` and an
   * optional dictionary of `options`.
   *
   * @param {String} writeKey
   * @param {Object} options (optional)
   *   @property {Number} flushAt (default: 20)
github kndt84 / aws-api-gateway-client / src / lib / apiGatewayCore / sigV4Client.js View on Github external
let signedRequest = {
      headers: headers,
      timeout: timeout,
      data: body
    };
    if (config.retries !== undefined) {
      signedRequest.baseURL = url;
      let client = axios.create(signedRequest);

      // Allow user configurable delay, or built-in exponential delay
      let retryDelay = function() {
 return 0;
};
      if (config.retryDelay === 'exponential') {
        retryDelay = axiosRetry.exponentialDelay;
      } else if (typeof config.retryDelay === 'number') {
        retryDelay = () => parseInt(config.retryDelay);
      } else if (typeof config.retryDelay === 'function') {
        retryDelay = config.retryDelay;
      }

      axiosRetry(client, {
        retries: config.retries,
        retryCondition: config.retryCondition,
        retryDelay,
      });
      return client.request({method: verb});
    }
    signedRequest.method = verb;
    signedRequest.url = url;
    return axios(signedRequest);
github kndt84 / aws-api-gateway-client / src / lib / apiGatewayCore / simpleHttpClient.js View on Github external
url += '?' + queryString;
    }

    let simpleHttpRequest = {
      headers: headers,
      timeout: timeout,
      data: body
    };
    if (config.retries !== undefined) {
      simpleHttpRequest.baseURL = url;
      let client = axios.create(simpleHttpRequest);

      // Allow user configurable delay, or built-in exponential delay
      let retryDelay = () => 0;
      if (config.retryDelay === 'exponential') {
        retryDelay = axiosRetry.exponentialDelay;
      } else if (typeof config.retryDelay === 'number') {
        retryDelay = () => parseInt(config.retryDelay);
      } else if (typeof config.retryDelay === 'function') {
        retryDelay = config.retryDelay;
      }

      axiosRetry(client, {
        retries: config.retries,
        retryCondition: config.retryCondition,
        retryDelay,
      });
      return client.request({method: verb});
    }
    simpleHttpRequest.method = verb;
    simpleHttpRequest.url = url;
    return axios(simpleHttpRequest);
github lifeomic / cli / lib / fhir.js View on Github external
// and will retry POST (normally POST requests are not
// retried since they are not idempotent, but in FHIR
// we use POST for searches and ingest, both of which are
// idempotent (assuming ingest uses client supplied ids
// which it usually does.), and will retry timeouts.
// This all makes ingest in particular much more reliable,
// which is important when ingesting large datasets.
const shouldRetry = error => {
  return axiosRetry.isNetworkError(error) ||
    axiosRetry.isRetryableError(error) ||
    error.code === 'ECONNABORTED' ||
    (error.response && error.response.status === 429);
};
const retryConfig = {
  retries: 5,
  retryDelay: axiosRetry.exponentialDelay,
  retryCondition: shouldRetry,
  shouldResetTimeout: true
};
axios.defaults.timeout = 16000; // 16 seconds

axios.defaults.headers.common['User-Agent'] = `${name}/${version}`;

function request (options) {
  const environment = config.getEnvironment();

  const account = options.account || config.get(`${environment}.defaults.account`);
  if (!account) {
    throw new Error(`Account needs to be set with 'lo defaults' or specified with the -a option.`);
  }

  const proxy = configureProxy.configureProxy();
github segmentio / analytics-node / index.js View on Github external
_isErrorRetryable (error) {
    // Retry Network Errors.
    if (axiosRetry.isNetworkError(error)) {
      return true
    }

    if (!error.response) {
      // Cannot determine if the request can be retried
      return false
    }

    // Retry Server Errors (5xx).
    if (error.response.status >= 500 && error.response.status <= 599) {
      return true
    }

    // Retry if rate limited.
    if (error.response.status === 429) {
      return true
github vtex / node-vtex-api / src / baseClient.js View on Github external
export function createClient (opts: ClientOptions): AxiosInstance {
  const {baseURL, authToken, userAgent, timeout = DEFAULT_TIMEOUT_MS} = opts

  const headers = {
    'Authorization': `bearer ${authToken}`,
    'User-Agent': userAgent,
  }

  const http = axios.create({
    baseURL,
    headers,
    timeout,
  })

  retry(http)

  http.interceptors.response.use(handleResponse, (err) => {
    if (err.response && err.response.config) {
      const {url, method} = err.response.config
      console.log(`Error calling ${method.toUpperCase()} ${url}`)
    }
    try {
      delete err.response.request
      delete err.response.config
      delete err.config.res
      delete err.config.data
    } catch (e) {}
    return Promise.reject(err)
  })

  return http
github vtex / node-vtex-api / src / utils / Retry.ts View on Github external
export const isNetworkErrorOrRouterTimeout = (e: any) => {
  if (isNetworkError(e)) {
    console.warn('Retry from network error', e.message)
    return true
  }

  if (e && e.response && e.response.data && e.response.data.code === TIMEOUT_CODE) {
    console.warn('Retry from timeout', e.message)
    return true
  }

  return false
}

axios-retry

Axios plugin that intercepts failed requests and retries them whenever posible.

Apache-2.0
Latest version published 4 months ago

Package Health Score

82 / 100
Full package analysis