0.0.5 • Published 7 years ago

axios-retry-tiny v0.0.5

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
7 years ago

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

optiontypedefaultdesc
retrynumber3times to retry
retryDelaynumber50ms time to delay retry
retryCodenumber, stringall error codethe match axios error code to retry
retryBeforeFnfunction(config)the function before retry, can get axios config

retryCode list

codetypedesc
'ECONNABORTED'stringtimeout
'ETIMEDOUT'stringtimeout
'ENOTFOUND'stringserver not found
'ENETUNREACH'stringnot reach
4**numberclient error
5**numberserver error

Thinks

Happy to thinks

License

Apache-2.0

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago