@empiricalrun/fetch
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

fetch

This module provides a fetch instance wrapper designed to handle retries and timeouts seamlessly. It offers the following features:

  • Retries: Specify the number of retries for failed requests. Default is set to 3.
  • Timeout: Set a timeout duration (in milliseconds) for requests. By default, there is no timeout.
  • Retry Condition: Define a custom function to determine whether a retry should be attempted. Installation

ou can install this module via npm:

npm install @empiricalrun/fetch

Usage

import {fetchWithRetry} from "@empiricalrun/fetch";

// Define shouldRetryFunction
function shouldRetry(response) {
    // Define your retry condition logic here
    return true;
}

// Usage example
const resp = await fetchWithRetry("<path>", { maxRetries: 2, timeout: 4000, shouldRetry });
const data = await resp.json();

Note: if the retry count has reached max value then shouldRetry cannot be called

/@empiricalrun/fetch/

    Package Sidebar

    Install

    npm i @empiricalrun/fetch

    Weekly Downloads

    2

    Version

    0.3.1

    License

    none

    Unpacked Size

    6.12 kB

    Total Files

    7

    Last publish

    Collaborators

    • siddharth11
    • saikatmitra
    • arjun27