Gathering detailed insights and metrics for fetch-retry-ts
Gathering detailed insights and metrics for fetch-retry-ts
Gathering detailed insights and metrics for fetch-retry-ts
Gathering detailed insights and metrics for fetch-retry-ts
npm install fetch-retry-ts
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
7 Stars
999 Commits
3 Forks
5 Watching
3 Branches
2 Contributors
Updated on 26 Nov 2024
TypeScript (97.08%)
JavaScript (2.92%)
Cumulative downloads
Total Downloads
Last day
-40.4%
1,948
Compared to previous day
Last week
-11.3%
13,044
Compared to previous week
Last month
5.2%
64,050
Compared to previous month
Last year
38.4%
714,464
Compared to previous year
Adds retry functionality to fetch()
.
1npm install fetch-retry-ts
1import originalFetch from 'isomorphic-fetch'; 2import fetchBuilder from 'fetch-retry-ts'; 3 4const options = { 5 retries: 3, 6 retryDelay: 1000, 7 retryOn: [419, 503, 504], 8}; 9 10const fetch = fetchBuilder(originalFetch, options); 11 12fetch('https://example.com/').then(/* ... */);
fetch-retry-ts
exports a function, which is used to build the new fetch()
-compatible function supporting the retry logic.
It accepts two arguments:
fetch
(required): the original fetch()
function (from isomorphic-fetch
etc)defaults
(optional): default values for the retry logic:
retries?: number
: number of attempts to make (3 by default);retryDelay?: number | () => number | (attempt: number, error: Error | null, response: Response | null) => number
: delay between attempts (in ms). If specified as a function, the function accepts the following parameters:
attempt
: the number of the current attempt;error
: Error
object coming from fetch()
when it rejects on a network failure, or null
;response
: Response
or null
if error !== null
It should return an integer, which is treated as the delay in ms before the enxt attempt is made. The default value for retryDelay
is 1000
.retryOn?: number[] | (attempt: number, retries: number, error: Error | null, response: Response | null) => boolean
: if specified as an array of integers, it is treated as a list of HTTP codes which trigger retry. When specified as a function, that functoin accepts the same parameters as the one described in retryDelay
, and an additional parameter called retries
, whcih is the number of configured retries. The function should return a truthy value if the request should be retried. If retryOn
is a function, retries
is ignored. The default value for retryOn
in [429, 503, 504]
.
It returns a function to be used instead of fetch()
.The returned function accepts the same arguments as fetch(input: RequestInfo, init?: RequestInit)
, and three additional properties in init
object. Those are retries
, retryDelay
, and retryOn
.
1fetch(url, { 2 retryOn: (attempt: number, retries: number, error: Error | null, response: Response | null): boolean => ( 3 attempt < retries && (!!error || !response || response.status >= 500) 4 ), 5}).then(/* ... */)
1fetch(url, { 2 retryOn: [], 3}).then(/* ... */)
1fetch(url, { 2 retryOn: (attempt: number, retries: number, error: Error | null, response: Response | null): boolean => ( 3 attempt < retries && error === null /* && additional logic to check response code */ 4 ), 5}).then(/* ... */)
1fetch(url, { 2 retryDelay: (attempt: number, error: Error | null, response: Response | null): number => ( 3 Math.pow(2, attempt) * 1000 4 ), 5}).then(/* ... */)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
all dependencies are pinned
Details
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
0 existing vulnerabilities detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More