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

2.0.1 • Public • Published

@soluzioni-futura/retry

A simple, dependency free, retry module.

Usage

In the following example, the Axios get function has been wrapped into a function that will be retried up to 3 times with a delay of 1000 ms between each retry. If the Axios call throws with a 500 status code the retry function will stop retrying and throws immediately the error.

import { retry, wait } from "@soluzioni-futura/retry"
import axios, { AxiosError } from "axios"

const shouldThrowFn = (err: AxiosError): boolean {
  return err.status === "500"
}

const options = {
  retryTimes: 3,
  retryDelay: 1000,
  shouldThrowFn: (err: AxiosError): boolean => err.status === "500"
}

retry(() => axios.get("https://soluzionifutura.it"), options)
  .then(res => console.log(res.status))
  .catch(axiosError => console.error(axiosError.status))

Available options

{
  retryTimes: number // number of maxium retries; default 3
  retryDelay: number // milliseconds beteween each retry; default 500
  shouldThrowFn: undefined | (err: any) => boolean // shouldThrowFn function is called each time a retry fails with an error; if true is returned the retry loop will immediately break throwing the error
}

Readme

Keywords

none

Package Sidebar

Install

npm i @soluzioni-futura/retry

Weekly Downloads

0

Version

2.0.1

License

ISC

Unpacked Size

19.5 kB

Total Files

12

Last publish

Collaborators

  • giovanni.bruno
  • nico.fuccella
  • vforvalerio87
  • zhoujian26
  • riccardorispoli
  • allemonta