2.0.1 • Published 2 years ago

@soluzioni-futura/retry v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@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
}
2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago