Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
// 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();
if (CB._isNode) {
Axios = require('Axios');
} else {
Axios = require('axios');
}
if (!isServiceUrl) {
var ssid = CB._getSessionId();
if (ssid != null)
headers.sessionID = ssid
}
if (params && typeof params != "object") {
params = JSON.parse(params);
}
axiosRetry(Axios, { retryDelay: axiosRetry.exponentialDelay });
Axios({
method: method,
url: url,
data: params,
headers: headers,
onUploadProgress: function (event) {
if (event.lengthComputable) {
var percentComplete = event.loaded / event.total;
if (progressCallback)
progressCallback(percentComplete)
}
}
}).then(function (res) {
if (!isServiceUrl) {
var sessionID = res.headers.sessionid
if (sessionID)
this.host = removeSlash(options.host || 'https://api.segment.io')
this.timeout = options.timeout || false
this.flushAt = Math.max(options.flushAt, 1) || 20
this.flushInterval = options.flushInterval || 10000
this.flushed = false
Object.defineProperty(this, 'enable', {
configurable: false,
writable: false,
enumerable: true,
value: typeof options.enable === 'boolean' ? options.enable : true
})
axiosRetry(axios, {
retries: options.retryCount || 3,
retryCondition: this._isErrorRetryable,
retryDelay: axiosRetry.exponentialDelay
})
}
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