Socket
Socket
Sign inDemoInstall

axios-retry

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-retry - npm Package Compare versions

Comparing version 3.8.1 to 3.8.2

17

index.d.ts

@@ -62,2 +62,17 @@ import * as axios from 'axios';

export interface IAxiosRetryConfigExtended extends IAxiosRetryConfig {
/**
* The number of times the request was retried
*
* @type {number}
*/
retryCount?: number;
/**
* The last time the request was retried (timestamp in milliseconds)
*
* @type {number}
*/
lastRequestTime?: number;
}
export interface IAxiosRetryReturn {

@@ -81,4 +96,4 @@ /**

export interface AxiosRequestConfig {
'axios-retry'?: IAxiosRetry.IAxiosRetryConfig;
'axios-retry'?: IAxiosRetry.IAxiosRetryConfigExtended;
}
}

90

lib/cjs/index.js

@@ -15,3 +15,3 @@ "use strict";

exports.default = axiosRetry;
exports.namespace = void 0;
exports.DEFAULT_OPTIONS = exports.namespace = void 0;

@@ -122,25 +122,37 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

}
/** @type {IAxiosRetryConfig} */
var DEFAULT_OPTIONS = {
retries: 3,
retryCondition: isNetworkOrIdempotentRequestError,
retryDelay: noDelay,
shouldResetTimeout: false,
onRetry: function onRetry() {}
};
/**
* Initializes and returns the retry state for the given request/config
* Returns the axios-retry options for the current request
* @param {AxiosRequestConfig} config
* @return {Object}
* @param {IAxiosRetryConfig} defaultOptions
* @return {IAxiosRetryConfigExtended}
*/
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
function getCurrentState(config) {
var currentState = config[namespace] || {};
currentState.retryCount = currentState.retryCount || 0;
config[namespace] = currentState;
return currentState;
function getRequestOptions(config, defaultOptions) {
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), defaultOptions), config[namespace]);
}
/**
* Returns the axios-retry options for the current request
* Initializes and returns the retry state for the given request/config
* @param {AxiosRequestConfig} config
* @param {AxiosRetryConfig} defaultOptions
* @return {AxiosRetryConfig}
* @param {IAxiosRetryConfig} defaultOptions
* @return {IAxiosRetryConfigExtended}
*/
function getRequestOptions(config, defaultOptions) {
return _objectSpread(_objectSpread({}, defaultOptions), config[namespace]);
function getCurrentState(config, defaultOptions) {
var currentState = getRequestOptions(config, defaultOptions);
currentState.retryCount = currentState.retryCount || 0;
config[namespace] = currentState;
return currentState;
}

@@ -167,12 +179,10 @@ /**

/**
* Checks retryCondition if request can be retried. Handles it's retruning value or Promise.
* @param {number} retries
* @param {Function} retryCondition
* @param {Object} currentState
* Checks retryCondition if request can be retried. Handles it's returning value or Promise.
* @param {IAxiosRetryConfigExtended} currentState
* @param {Error} error
* @return {boolean}
* @return {Promise<boolean>}
*/
function shouldRetry(_x, _x2, _x3, _x4) {
function shouldRetry(_x, _x2) {
return _shouldRetry.apply(this, arguments);

@@ -239,4 +249,4 @@ }

function _shouldRetry() {
_shouldRetry = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(retries, retryCondition, currentState, error) {
var shouldRetryOrPromise, shouldRetryPromiseResult;
_shouldRetry = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(currentState, error) {
var retries, retryCondition, shouldRetryOrPromise, shouldRetryPromiseResult;
return _regenerator.default.wrap(function _callee2$(_context2) {

@@ -246,26 +256,27 @@ while (1) {

case 0:
retries = currentState.retries, retryCondition = currentState.retryCondition;
shouldRetryOrPromise = currentState.retryCount < retries && retryCondition(error); // This could be a promise
if (!((0, _typeof2.default)(shouldRetryOrPromise) === 'object')) {
_context2.next = 12;
_context2.next = 13;
break;
}
_context2.prev = 2;
_context2.next = 5;
_context2.prev = 3;
_context2.next = 6;
return shouldRetryOrPromise;
case 5:
case 6:
shouldRetryPromiseResult = _context2.sent;
return _context2.abrupt("return", shouldRetryPromiseResult !== false);
case 9:
_context2.prev = 9;
_context2.t0 = _context2["catch"](2);
case 10:
_context2.prev = 10;
_context2.t0 = _context2["catch"](3);
return _context2.abrupt("return", false);
case 12:
case 13:
return _context2.abrupt("return", shouldRetryOrPromise);
case 13:
case 14:
case "end":

@@ -275,3 +286,3 @@ return _context2.stop();

}
}, _callee2, null, [[2, 9]]);
}, _callee2, null, [[3, 10]]);
}));

@@ -283,3 +294,3 @@ return _shouldRetry.apply(this, arguments);

var requestInterceptorId = axios.interceptors.request.use(function (config) {
var currentState = getCurrentState(config);
var currentState = getCurrentState(config, defaultOptions);
currentState.lastRequestTime = Date.now();

@@ -290,4 +301,3 @@ return config;

var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(error) {
var config, _getRequestOptions, _getRequestOptions$re, retries, _getRequestOptions$re2, retryCondition, _getRequestOptions$re3, retryDelay, _getRequestOptions$sh, shouldResetTimeout, _getRequestOptions$on, onRetry, currentState, delay, lastRequestDuration, timeout;
var config, currentState, retryDelay, shouldResetTimeout, onRetry, delay, lastRequestDuration, timeout;
return _regenerator.default.wrap(function _callee$(_context) {

@@ -307,8 +317,7 @@ while (1) {

case 3:
_getRequestOptions = getRequestOptions(config, defaultOptions), _getRequestOptions$re = _getRequestOptions.retries, retries = _getRequestOptions$re === void 0 ? 3 : _getRequestOptions$re, _getRequestOptions$re2 = _getRequestOptions.retryCondition, retryCondition = _getRequestOptions$re2 === void 0 ? isNetworkOrIdempotentRequestError : _getRequestOptions$re2, _getRequestOptions$re3 = _getRequestOptions.retryDelay, retryDelay = _getRequestOptions$re3 === void 0 ? noDelay : _getRequestOptions$re3, _getRequestOptions$sh = _getRequestOptions.shouldResetTimeout, shouldResetTimeout = _getRequestOptions$sh === void 0 ? false : _getRequestOptions$sh, _getRequestOptions$on = _getRequestOptions.onRetry, onRetry = _getRequestOptions$on === void 0 ? function () {} : _getRequestOptions$on;
currentState = getCurrentState(config);
_context.next = 7;
return shouldRetry(retries, retryCondition, currentState, error);
currentState = getCurrentState(config, defaultOptions);
_context.next = 6;
return shouldRetry(currentState, error);
case 7:
case 6:
if (!_context.sent) {

@@ -320,2 +329,3 @@ _context.next = 21;

currentState.retryCount += 1;
retryDelay = currentState.retryDelay, shouldResetTimeout = currentState.shouldResetTimeout, onRetry = currentState.onRetry;
delay = retryDelay(currentState.retryCount, error); // Axios fails merging this configuration to the default configuration because it has an issue

@@ -369,3 +379,3 @@ // with circular structures: https://github.com/mzabriskie/axios/issues/370

return function (_x5) {
return function (_x3) {
return _ref.apply(this, arguments);

@@ -372,0 +382,0 @@ };

@@ -95,24 +95,34 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

}
/** @type {IAxiosRetryConfig} */
export var DEFAULT_OPTIONS = {
retries: 3,
retryCondition: isNetworkOrIdempotentRequestError,
retryDelay: noDelay,
shouldResetTimeout: false,
onRetry: () => {}
};
/**
* Initializes and returns the retry state for the given request/config
* Returns the axios-retry options for the current request
* @param {AxiosRequestConfig} config
* @return {Object}
* @param {IAxiosRetryConfig} defaultOptions
* @return {IAxiosRetryConfigExtended}
*/
function getCurrentState(config) {
var currentState = config[namespace] || {};
currentState.retryCount = currentState.retryCount || 0;
config[namespace] = currentState;
return currentState;
function getRequestOptions(config, defaultOptions) {
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), defaultOptions), config[namespace]);
}
/**
* Returns the axios-retry options for the current request
* Initializes and returns the retry state for the given request/config
* @param {AxiosRequestConfig} config
* @param {AxiosRetryConfig} defaultOptions
* @return {AxiosRetryConfig}
* @param {IAxiosRetryConfig} defaultOptions
* @return {IAxiosRetryConfigExtended}
*/
function getRequestOptions(config, defaultOptions) {
return _objectSpread(_objectSpread({}, defaultOptions), config[namespace]);
function getCurrentState(config, defaultOptions) {
var currentState = getRequestOptions(config, defaultOptions);
currentState.retryCount = currentState.retryCount || 0;
config[namespace] = currentState;
return currentState;
}

@@ -139,12 +149,10 @@ /**

/**
* Checks retryCondition if request can be retried. Handles it's retruning value or Promise.
* @param {number} retries
* @param {Function} retryCondition
* @param {Object} currentState
* Checks retryCondition if request can be retried. Handles it's returning value or Promise.
* @param {IAxiosRetryConfigExtended} currentState
* @param {Error} error
* @return {boolean}
* @return {Promise<boolean>}
*/
function shouldRetry(_x, _x2, _x3, _x4) {
function shouldRetry(_x, _x2) {
return _shouldRetry.apply(this, arguments);

@@ -211,3 +219,7 @@ }

function _shouldRetry() {
_shouldRetry = _asyncToGenerator(function* (retries, retryCondition, currentState, error) {
_shouldRetry = _asyncToGenerator(function* (currentState, error) {
var {
retries,
retryCondition
} = currentState;
var shouldRetryOrPromise = currentState.retryCount < retries && retryCondition(error); // This could be a promise

@@ -232,3 +244,3 @@

var requestInterceptorId = axios.interceptors.request.use(config => {
var currentState = getCurrentState(config);
var currentState = getCurrentState(config, defaultOptions);
currentState.lastRequestTime = Date.now();

@@ -247,13 +259,11 @@ return config;

var {
retries = 3,
retryCondition = isNetworkOrIdempotentRequestError,
retryDelay = noDelay,
shouldResetTimeout = false,
onRetry = () => {}
} = getRequestOptions(config, defaultOptions);
var currentState = getCurrentState(config);
var currentState = getCurrentState(config, defaultOptions);
if (yield shouldRetry(retries, retryCondition, currentState, error)) {
if (yield shouldRetry(currentState, error)) {
currentState.retryCount += 1;
var {
retryDelay,
shouldResetTimeout,
onRetry
} = currentState;
var delay = retryDelay(currentState.retryCount, error); // Axios fails merging this configuration to the default configuration because it has an issue

@@ -283,3 +293,3 @@ // with circular structures: https://github.com/mzabriskie/axios/issues/370

return function (_x5) {
return function (_x3) {
return _ref.apply(this, arguments);

@@ -286,0 +296,0 @@ };

{
"name": "axios-retry",
"version": "3.8.1",
"version": "3.8.2",
"author": "Rubén Norte <ruben.norte@softonic.com>",

@@ -5,0 +5,0 @@ "description": "Axios plugin that intercepts failed requests and retries them whenever posible.",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc