@axios-plugin/retry
TypeScript icon, indicating that this package has built-in type declarations

0.0.5-alpha.0 • Public • Published

@axios-plugin/retry

拦截失败的请求并在可能的情况下进行重试

安装

yarn add @axios-plugin/retry

使用

import { RetryPlugin } from '@axios-plugin/retry'

axiosInstance = 
  pluginify(axios.create() as AxiosStatic).use(new RetryPlugin({ retries: 2 }).generate()

参数可选,默认情况下会重试三次

参数

new RetryPlugin()
new RetryPlugin(config)

该 Plugin 是对 axios-retry 的封装,所以参数和 axios-retry 保持一致。

Name Type Default Description
retries Number 3 The number of times to retry before failing. 1 = One retry after first failure
retryCondition Function isNetworkOrIdempotentRequestError A callback to further control if a request should be retried. By default, it retries if it is a network error or a 5xx error on an idempotent request (GET, HEAD, OPTIONS, PUT or DELETE).
shouldResetTimeout Boolean false Defines if the timeout should be reset between retries
retryDelay Function function noDelay() { return 0; } A callback to further control the delay in milliseconds between retried requests. By default there is no delay between retries. Another option is exponentialDelay (Exponential Backoff). The function is passed retryCount and error.
onRetry Function function onRetry(retryCount, error, requestConfig) { return; } A callback to notify when a retry is about to occur. Useful for tracing. By default nothing will occur. The function is passed retryCount, error, and requestConfig.

注意

在使用 TimeoutPlugin 时,首先需要使用 pluginify 将 axios变成基于插件的请求库. pluginify 内置在 @axios-plugin/core 中.

Package Sidebar

Install

npm i @axios-plugin/retry

Weekly Downloads

2

Version

0.0.5-alpha.0

License

MIT

Unpacked Size

5.15 kB

Total Files

6

Last publish

Collaborators

  • mengqiuleo