Gathering detailed insights and metrics for @adobe/node-fetch-retry
Gathering detailed insights and metrics for @adobe/node-fetch-retry
Gathering detailed insights and metrics for @adobe/node-fetch-retry
Gathering detailed insights and metrics for @adobe/node-fetch-retry
async-retry
Retrying made simple, easy and async
p-retry
Retry a promise-returning or async function
fetch-retry
Extend any fetch library with retry functionality
@vercel/fetch-retry
[![Build Status](https://github.com/vercel/fetch/workflows/CI/badge.svg)](https://github.com/vercel/fetch/actions?workflow=CI)
npm install @adobe/node-fetch-retry
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
44 Stars
89 Commits
21 Forks
23 Watching
14 Branches
242 Contributors
Updated on 04 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-24.3%
2,814
Compared to previous day
Last week
6.5%
15,159
Compared to previous week
Last month
7.2%
56,648
Compared to previous month
Last year
41.5%
599,810
Compared to previous year
Node Module for performing retries for HTTP requests.
It is a wrapper around node-fetch
library. It has default retry logic built in as described below, as well as configurable parameters. It also has built-in support for Apache OpenWhisk actions, adjusting the timeout to reflect the action timeout.
1npm install @adobe/node-fetch-retry
This library works the same as the normal fetch api
, but with some added features.
Without configuring any parameters, the retry behavior will be as follows:
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url); 5}
This example uses only custom headers and will use default retry settings:
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 headers: { 6 'custom-header': '<<put custom header value here>>' 7 } 8 }); 9}
All the retry options are configurable and can be set in retryOptions
in the options
object passed to fetch
.
Parameter | Format | Description | Environment variable | Default Value |
---|---|---|---|---|
retryMaxDuration | Number | time in milliseconds to retry until throwing an error | NODE_FETCH_RETRY_MAX_RETRY | 60000 ms |
retryInitialDelay | Number | time in milliseconds to wait between retries | NODE_FETCH_RETRY_INITIAL_WAIT | 100 ms |
retryBackoff | Number | backoff factor for wait time between retries | NODE_FETCH_RETRY_BACKOFF | 2.0 |
retryOnHttpResponse | Function | a function determining whether to retry given the HTTP response. Can be asynchronous | none | retry on all 5xx errors |
retryOnHttpError | Function | a function determining whether to retry given the HTTP error exception thrown. Can be asynchronous | none | retry on all FetchError 's of type system |
socketTimeout | Number | time until socket timeout in milliseconds. Note: if socketTimeout is >= retryMaxDuration , it will automatically adjust the socket timeout to be exactly half of the retryMaxDuration . To disable this feature, see forceSocketTimeout below | NODE_FETCH_RETRY_SOCKET_TIMEOUT | 30000 ms |
forceSocketTimeout | Boolean | If true, socket timeout will be forced to use socketTimeout property declared regardless of the retryMaxDuration . Note: this feature was designed to help with unit testing and is not intended to be used in practice | NODE_FETCH_RETRY_FORCE_TIMEOUT | false |
Note: the environment variables override the default values if the corresponding parameter is not set. These are designed to help with unit testing. Passed in parameters will still override the environment variables
This example decreases the retryMaxDuration
and makes the retry delay a static 500ms. This will do no more than 4 retries.
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 retryOptions: { 6 retryMaxDuration: 2000, // 30s retry max duration 7 retryInitialDelay: 500, 8 retryBackoff: 1.0 // no backoff 9 } 10 }); 11}
This example shows how to configure retries on specific HTTP responses:
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 retryOptions: { 6 retryOnHttpResponse: function (response) { 7 if ( (response.status >= 500) || response.status >= 400) { // retry on all 5xx and all 4xx errors 8 return true; 9 } 10 } 11 } 12 }); 13}
This example uses custom socketTimeout
values:
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 retryOptions: { 6 retryMaxDuration: 300000, // 5min retry duration 7 socketTimeout: 60000, // 60s socket timeout 8 } 9 }); 10}
This example uses custom socketTimeout
values and custom headers:
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 retryOptions: { 6 retryMaxDuration: 300000, // 5min retry duration 7 socketTimeout: 60000, // 60s socket timeout 8 }, 9 headers: { 10 'custom-header': '<<put custom header value here>>' 11 } 12 }); 13}
This example shows how to retry on all HTTP errors thrown as an exception:
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 retryOptions: { 6 retryOnHttpError: function (error) { 7 return true; 8 } 9 } 10 }); 11}
You can disable all retry behavior by setting retryOptions
to false
.
1const fetch = require('@adobe/node-fetch-retry'); 2 3async main() { 4 const response = await fetch(url, { 5 retryOptions: false 6 }); 7}
Disabling retry behavior will not prevent the usage of other options set on the options
object.
If the fetch is unsuccessful, the retry logic determines how long it will wait before the next attempt. If the time remaining will exceed the total time allowed by retryMaxDuration then another attempt will not be made. There are examples of how this works in the testing code.
If you are running this in the context of an OpenWhisk action, it will take into account the action timeout deadline when setting the retryMaxDuration
. It uses the __OW_ACTION_DEADLINE
environment variable to determine if there is an action running.
Behavior:
If retryMaxDuration
is greater than the time till the action will timeout, it will adjust the retryMaxDuration
to be equal to the time till action timeout.
Contributions are welcomed! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 13/22 approved changesets -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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