How to use the axios-retry function in axios-retry

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 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 envkey / envkey-app / envkey-react / src / lib / s3 / index.js View on Github external
import axios from 'axios'
import axiosRetry from 'axios-retry'
import R from 'ramda'

const client = axios.create({timeout: 3000})

axiosRetry(client, {
  retries: 5,
  retryDelay: axiosRetry.exponentialDelay,
  retryCondition: R.always(true),
  shouldResetTimeout: true
})

export const s3Client = client
github topheman / npm-registry-browser / src / services / apis / httpClient.js View on Github external
export const makeClient = ({
  retries = 3,
  retryDelay = fibonacciRetryDelay(),
  ...axiosConfig
}) => {
  const client = axios.create(axiosConfig);
  /*
   * If the network or the api server fails a request, the client will
   * retry 3 times until the request goes through
   * Only applied to idempotent requests:
   * - method GET/HEAD/OPTIONS/PUT/DELETE
   * - 5xx server error
   * - network errors
   */
  if (retries) {
    axiosRetry(client, { retries, retryDelay });
  }
  return client;
};
github envkey / envkey-app / envkey-react / src / lib / api / index.js View on Github external
import axios from 'axios'
import R from 'ramda'
import axiosRetry from 'axios-retry'

export const API_VERSION = "v1"

const
  opts =  {
    baseURL: [process.env.API_HOST, API_VERSION].join("/"),
    timeout: 120000
  },

  defaultClient = axios.create(opts)

axiosRetry(defaultClient, {retries: 3})

export const authenticatedClient = (auth={})=> {
  const client = axios.create({
    ...opts,
    headers: R.pick(["access-token", "uid", "client"], auth)
  })
  axiosRetry(client, {retries: 3})
  return client
}

export default defaultClient
github topheman / nextjs-movie-browser / src / libs / apis-manager / http-client.ts View on Github external
export const makeClient = ({
  retries = 3,
  retryDelay = fibonacciRetryDelay(),
  ...axiosConfig
}) => {
  const client = axios.create(axiosConfig);
  /*
   * If the network or the api server fails a request, the client will
   * retry 3 times until the request goes through
   * Only applied to idempotent requests:
   * - method GET/HEAD/OPTIONS/PUT/DELETE
   * - 5xx server error
   * - network errors
   */
  if (retries) {
    axiosRetry(client, { retries, retryDelay });
  }
  return client;
};
github vtex / node-vtex-api / src / HttpClient / middlewares / request.ts View on Github external
import { renameBy } from '../../utils/renameBy'
import { isAbortedOrNetworkErrorOrRouterTimeout } from '../../utils/retry'
import { MiddlewareContext } from '../typings'

const httpAgent = new Agent({
  freeSocketTimeout: 15 * 1000,
  keepAlive: true,
  maxFreeSockets: 50,
})

const http = axios.create({
  httpAgent,
})

retry(http, {
  retries: 0,
  retryCondition: isAbortedOrNetworkErrorOrRouterTimeout,
  retryDelay: exponentialDelay,
  shouldResetTimeout: true,
})

const paramsSerializer = (params: any) => {
  return stringify(params, {arrayFormat: 'repeat'})
}

export const defaultsMiddleware = (baseURL: string | undefined, rawHeaders: Record, params: Record | undefined, timeout: number, retries?: number, verbose?: boolean) => {
  const countByMetric: Record = {}
  const headers = renameBy(toLower, rawHeaders)
  return async (ctx: MiddlewareContext, next: () => Promise) => {
    ctx.config = {
      'axios-retry': retries ? { retries } : undefined,

axios-retry

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

Apache-2.0
Latest version published 2 months ago

Package Health Score

85 / 100
Full package analysis

Similar packages