项目作者: flexdinesh

项目描述 :
Configurable Axios Interceptor to retry failed http calls.
高级语言: JavaScript
项目地址: git://github.com/flexdinesh/axios-retry-interceptor.git
创建时间: 2018-02-13T20:49:30Z
项目社区:https://github.com/flexdinesh/axios-retry-interceptor

开源协议:MIT License

下载


Axios Retry Interceptor

Build Status
dependencies Status
npm version
License: MIT

Configurable Axios Interceptor to retry failed http calls.

Install

  1. npm install --save axios-retry-interceptor

Usage

Import

  1. import retryInterceptor from 'axios-retry-interceptor';
  2. // or
  3. const retryInterceptor = require('axios-retry-interceptor');

Set the interceptor for your axios instance. Voila! ✨

  1. retryInterceptor(axios, {
  2. maxAttempts: 3,
  3. waitTime: 1000
  4. });

API

retryInterceptor(axiosInstance, options)

  • axiosInstance - your axios instance
  • options - config for retry interceptor

Options

maxAttempts

Max number of times the interceptor should retry the failed http call.

Type: Number

Default: 3

Example: maxAttempts: 5

waitTime

Duration between each retry attempt in milliseconds(1s=1000ms).

Type: Number

Default: 0

Example: waitTime: 3000

errorCodes

Response errorCodes for which the interceptor should retry.

Ideally any implementation should retry only 5xx status(server errors) and should not retry 4xx status(client errors). The reason is, if a http call fails with a client error, then the retry call will have the same headers/params and will obviously fail. So by default all 5xx errors will be retried. If you want to customize the status for which the retries should be made, use this config.

Type: Array

Default: []

Example: errorCodes: [500, 501, 401]

Author’s note

Ideally only idempotent http methods (GET, PUT, DELETE, HEAD, OPTIONS) should be retried on failed http calls. Non-idempotent methods like POST should NOT be retried and that’s why this library will not permit retry of non-idempotent methods.

License

MIT © Dinesh Pandiyan