Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
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);
};
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 ) {
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)
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
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
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;
};
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
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;
};
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,