http-retries
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

retry

为 Fetch 增加重试功能

import { enhanceFetchRetry as createFetchRetry } from "../../lib/fecth";

const successURL = "https://jsonplaceholder.typicode.com/todos/1";
const errorURL = successURL + "error";

const myFetch = createFetchRetry(fetch, {
  retries: 5,
  delay: 1000,
  condition: function (
    promiseResponse,
    response,
    count,
    context,
    retryOptions
  ) {
    console.log(count);
    if (count >= 2) {
      context.input = successURL;
    }
    return response.status === 404;
  },
});

myFetch(errorURL)
  .then((res) => {
    console.log("Success", res);
  })
  .catch((...errors) => {
    console.log(errors);
  });

Dependencies (0)

    Dev Dependencies (9)

    Package Sidebar

    Install

    npm i http-retries

    Weekly Downloads

    2

    Version

    0.1.0

    License

    ISC

    Unpacked Size

    15 kB

    Total Files

    18

    Last publish

    Collaborators

    • kenny6520