Skip to content

Latest commit

 

History

History

plugin-retry

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@plantae/plugin-retry

Retry plugin for Plantae.

It's highly inspired by Ky's retry

Installation

# npm
npm install @plantae/plugin-retry

# yarn
yarn add @plantae/plugin-retry

Usage

import retryPlugin from "@plantae/plugin-retry";

const fetchWithRetry = createFetch({
  client: fetch,
  plugins: [retryPlugin(3)], // retry 3 times
});

Or, you can pass the options:

const fetchWithRetry = createFetch({
  client: fetch,
  plugins: [
    retryPlugin({
      limit: 3,
      methods: ["GET", "POST"],
      statusCodes: [408, 429],
      maxRetryAfter: 1000,
      backoffLimit: 10000,
    }),
  ],
});

Options

type PluginOptions =
  | {
      // default: 2
      limit?: number;

      // default: ["GET", "PUT", "HEAD", "OPTIONS", "DELETE"]
      methods?: string[];

      // default: [408, 413, 429, 500, 502, 503, 504]
      statusCodes?: number[];

      // default: undefined
      maxRetryAfter?: number;

      // default: undefined
      backoffLimit?: number;
    }
  | number;