Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.0.0 to 3.0.1

18

CHANGELOG.md

@@ -8,8 +8,18 @@ # Change Log

## [3.0.1] - 2017-08-16
### Fixed
- Fixed first request time not being taken into account in timeout across retries.
- Fixed negative timeouts being passed to XHR (browsers), causing that no timeout was applied.
- Fixed safe methods and idempotent errors not being retried on unknown network errors.
## [3.0.0] - 2017-08-13
### Changed
- Retried errors on idempotent requests (5xx with get, head, options, put and delete) by default,
along with network errors.
along with safe network errors.
- Moved some hard-coded conditions to the default `retryCondition` function so users can define a
custom function that overwrites them. The conditions that verify that the error is not a timeout or an unsafe network error have been moved to `isNetworkError`.
custom function that overwrites them. The conditions that verify that the error is not a timeout or
an unsafe network error have been moved to `isNetworkError`.
### Added

@@ -19,2 +29,3 @@ - Added additional pre-defined retry conditions: `isSafeRequestError`, `isIdempotentRequestError`.

## [2.0.1] - 2017-06-19
### Fixed

@@ -24,2 +35,3 @@ - Removed dependency from the `package.json` file.

## [2.0.0] - 2017-06-15
### Changed

@@ -29,2 +41,3 @@ - Now the configured timeout in Axios is not for each retry request but for the whole request lifecycle.

## [1.3.1] - 2017-06-19
### Fixed

@@ -34,3 +47,4 @@ - Removed dependency from the `package.json` file.

## [1.3.0] - 2017-06-15
### Added
- Allowed per-request configuration using the `axios-retry` namespace.

33

es/index.js

@@ -23,9 +23,18 @@ import isRetryAllowed from 'is-retry-allowed';

*/
function isRetryableError(error) {
return error.code !== 'ECONNABORTED'
&& (!error.response || (error.response.status >= 500 && error.response.status <= 599));
}
/**
* @param {Error} error
* @return {boolean}
*/
export function isSafeRequestError(error) {
if (!error.response || !error.config) {
if (!error.config) {
// Cannot determine if the request can be retried
return false;
}
return error.response.status >= 500 && error.response.status <= 599
&& SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
}

@@ -38,8 +47,8 @@

export function isIdempotentRequestError(error) {
if (!error.response || !error.config) {
if (!error.config) {
// Cannot determine if the request can be retried
return false;
}
return error.response.status >= 500 && error.response.status <= 599
&& IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
}

@@ -134,2 +143,8 @@

export default function axiosRetry(axios, defaultOptions) {
axios.interceptors.request.use((config) => {
const currentState = getCurrentState(config);
currentState.lastRequestTime = Date.now();
return config;
});
axios.interceptors.response.use(null, error => {

@@ -160,7 +175,7 @@ const config = error.config;

const now = Date.now();
if (config.timeout && currentState.lastRequestTime) {
config.timeout -= now - currentState.lastRequestTime;
const lastRequestDuration = Date.now() - currentState.lastRequestTime;
// Minimum 1ms timeout (passing 0 or less to XHR means no timeout)
config.timeout = Math.max(config.timeout - lastRequestDuration, 1);
}
currentState.lastRequestTime = now;

@@ -167,0 +182,0 @@ return axios(config);

@@ -37,8 +37,17 @@ 'use strict';

*/
function isRetryableError(error) {
return error.code !== 'ECONNABORTED' && (!error.response || error.response.status >= 500 && error.response.status <= 599);
}
/**
* @param {Error} error
* @return {boolean}
*/
function isSafeRequestError(error) {
if (!error.response || !error.config) {
if (!error.config) {
// Cannot determine if the request can be retried
return false;
}
return error.response.status >= 500 && error.response.status <= 599 && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
}

@@ -51,7 +60,8 @@

function isIdempotentRequestError(error) {
if (!error.response || !error.config) {
if (!error.config) {
// Cannot determine if the request can be retried
return false;
}
return error.response.status >= 500 && error.response.status <= 599 && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
}

@@ -146,2 +156,8 @@

function axiosRetry(axios, defaultOptions) {
axios.interceptors.request.use(function (config) {
var currentState = getCurrentState(config);
currentState.lastRequestTime = Date.now();
return config;
});
axios.interceptors.response.use(null, function (error) {

@@ -172,7 +188,7 @@ var config = error.config;

var now = Date.now();
if (config.timeout && currentState.lastRequestTime) {
config.timeout -= now - currentState.lastRequestTime;
var lastRequestDuration = Date.now() - currentState.lastRequestTime;
// Minimum 1ms timeout (passing 0 or less to XHR means no timeout)
config.timeout = Math.max(config.timeout - lastRequestDuration, 1);
}
currentState.lastRequestTime = now;

@@ -179,0 +195,0 @@ return axios(config);

{
"name": "axios-retry",
"version": "3.0.0",
"version": "3.0.1",
"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

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