Skip to content

phantomk/axios-retry-tiny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

axios-retry-tiny

CircleCI npm-veriosn npm-dt

A tiny interceptor for axios to retry request

Install

npm i axios-retry-tiny --save
# or use yarn
yarn add axios-retry-tiny

Use

const axios = require('axios');
const artiny = require('axios-retry-tiny');
artiny(axios);

(async () => {
  try {
    await axios({
      url: 'https://google.com',
      method: 'get',
      retry: 5,
      retryDelay: 100,
      retryCode: ['ECONNABORTED', 'ETIMEDOUT', 500],
      retryBeforeFn: (e) => {
        console.log(`retry #${e.config.__retryCount}: ${e.config.url} : errCode: ${e.code || (e.response && e.response.status)}`);
      }
    });
  } catch (error) {
    console.log(error);
  }
})();

Option

option type default desc
retry number 3 times to retry
retryDelay number 50 ms time to delay retry
retryCode [number, string] all error code the match axios error code to retry
retryBeforeFn function(config) the function before retry, can get axios config

retryCode list

code type desc
'ECONNABORTED' string timeout
'ETIMEDOUT' string timeout
'ENOTFOUND' string server not found
'ENETUNREACH' string not reach
4** number client error
5** number server error

Thinks

Happy to thinks

License

Apache-2.0

About

a tiny interceptor for axios to retry request

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published