Registry / devops / retry-my-fetch

retry-my-fetch

JSON →
library1.4.1jsnpmunverified

A decorator for the Fetch API (native, isomorphic-fetch, cross-fetch) that adds configurable automatic retry logic with support for timeouts, AbortController, JWT token refresh via beforeRefetch callback, and status-code-based skip logic. Version 1.4.1 is stable with TypeScript declarations included. Differentiators: lightweight (no dependencies), promise-based retry with max count, timeout between retries, and a flexible beforeRefetch hook for modifying requests on each attempt.

npm install retry-my-fetch
INSTALL
IMPORT
SIG · RETRY-MY-FETCH
R
retry-my-fetch
devopsjavascriptv1.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import retryMyFetch from 'retry-my-fetch'
const retryMyFetch = require('retry-my-fetch')
Package is ESM-only; CommonJS require() will fail unless using dynamic import.
RetryMyFetchConfig
import retryMyFetch, { RetryMyFetchConfig } from 'retry-my-fetch'
import { RetryMyFetchConfig } from 'retry-my-fetch'
The config type is exported separately. Incorrectly assuming it's on the default export leads to TS errors.
typeof retryMyFetch
import type { RetryMyFetch } from 'retry-my-fetch'
For the type of the decorated fetch function itself, import the type alias RetryMyFetch.

Shows basic setup with max retries, timeout, and status code exclusions using TypeScript types.

import retryMyFetch from 'retry-my-fetch'; const config = { maxTryCount: 5, timeout: 2000, doNotRetryIfStatuses: [400, 401], }; const fetchWithRetry = retryMyFetch(fetch, config); fetchWithRetry('https://api.example.com/data') .then(async response => { if (!response.ok) throw new Error('Fetch failed'); return response.json(); }) .then(data => console.log(data)) .catch(err => console.error(err));
Debug
Known issues
gotchaThe beforeRefetch callback receives retryConter (misspelled) as the 4th parameter - note the typo in the parameter name
fix
Access the parameter as retryConter (the actual name used in the source), or rename in your code for clarity
affects: >=1.0.0
gotchaThe timeout option adds a delay before each retry attempt, not a total request timeout
fix
Use timeout for inter-retry delay; for total timeout, combine with AbortSignal.timeout()
affects: >=1.0.0
gotchaIf using AbortController with useAbortController: true, the AbortController is created internally for each retry; passing an external signal will be overridden
fix
Do not pass your own signal if useAbortController is true; the library manages the signal
affects: >=1.0.0
gotchaThe doNotRetryIfStatuses option uses an array of numbers; passing a set or other iterable may cause type errors
fix
Ensure the value is a plain array of numbers, e.g., [400, 401]
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: retryMyFetch is not a function
Using CommonJS require() on an ESM-only package
fix
Use import retryMyFetch from 'retry-my-fetch' or dynamic import()
Cannot find module 'retry-my-fetch' or its corresponding type declarations
Missing @types/retry-my-fetch or package not installed
fix
Install the package: npm install retry-my-fetch (types are bundled)
Property 'maxTryCount' does not exist on type '{ maxTryCount?: any; ... }'
Misspelling of maxTryCount (correct: maxTryCount)
fix
Use correct property names: maxTryCount, timeout, beforeRefetch, etc.
AbortError: signal is aborted without the user throwing
AbortController timed out or was manually aborted; retry logic may not handle it as expected
fix
Configure timeout appropriately or avoid using abort signals that may fire during retries
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
retry-my-fetch — npm install retry-my-fetch · libregistry