Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vercel/fetch-retry

Package Overview
Dependencies
Maintainers
12
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/fetch-retry - npm Package Compare versions

Comparing version 5.0.2 to 5.0.3

.github/workflows/test.yml

48

index.js

@@ -12,2 +12,10 @@ const retry = require('async-retry');

function isClientError(err) {
if (!err) return false;
return (
err.code === 'ERR_UNESCAPED_CHARACTERS' ||
err.message === 'Request path contains unescaped characters'
);
}
function setup(fetch) {

@@ -19,13 +27,16 @@ if (!fetch) {

async function fetchRetry(url, opts = {}) {
const retryOpts = Object.assign({
// timeouts will be [10, 60, 360, 2160, 12960]
// (before randomization is added)
minTimeout: MIN_TIMEOUT,
retries: MAX_RETRIES,
factor: FACTOR,
maxRetryAfter: MAX_RETRY_AFTER,
}, opts.retry);
const retryOpts = Object.assign(
{
// timeouts will be [10, 60, 360, 2160, 12960]
// (before randomization is added)
minTimeout: MIN_TIMEOUT,
retries: MAX_RETRIES,
factor: FACTOR,
maxRetryAfter: MAX_RETRY_AFTER,
},
opts.retry
);
if (opts.onRetry) {
retryOpts.onRetry = error => {
retryOpts.onRetry = (error) => {
opts.onRetry(error, opts);

@@ -35,3 +46,3 @@ if (opts.retry && opts.retry.onRetry) {

}
}
};
}

@@ -41,3 +52,3 @@

return await retry(async (bail, attempt) => {
const {method = 'GET'} = opts;
const { method = 'GET' } = opts;
try {

@@ -54,3 +65,3 @@ // this will be retried

} else {
await new Promise(r => setTimeout(r, retryAfter * 1e3));
await new Promise((r) => setTimeout(r, retryAfter * 1e3));
}

@@ -63,6 +74,11 @@ }

} catch (err) {
const isClientError = err && err.code === 'ERR_UNESCAPED_CHARACTERS';
const isRetry = !isClientError && attempt <= retryOpts.retries;
debug(`${method} ${url} error (status = ${err.status}). ${isRetry ? 'retrying' : ''}`, err);
if (isClientError) {
const clientError = isClientError(err);
const isRetry = !clientError && attempt <= retryOpts.retries;
debug(
`${method} ${url} error (status = ${err.status}). ${
isRetry ? 'retrying' : ''
}`,
err
);
if (clientError) {
return bail(err);

@@ -69,0 +85,0 @@ }

{
"name": "@vercel/fetch-retry",
"version": "5.0.2",
"version": "5.0.3",
"license": "MIT",
"devDependencies": {
"jest": "^21.2.1",
"node-fetch": "^1.7.3"
"node-fetch": "^2.6.1"
},

@@ -9,0 +9,0 @@ "peerDependencies": {

@@ -1,3 +0,5 @@

# fetch-retry [![CircleCI](https://circleci.com/gh/vercel/fetch-retry.svg?style=svg)](https://circleci.com/gh/vercel/fetch-retry)
# fetch-retry
[![Build Status](https://github.com/zeit/fetch-retry/workflows/Node%20CI/badge.svg)](https://github.com/zeit/fetch-retry/actions?workflow=Node+CI)
A layer on top of `fetch` (via [node-fetch](https://www.npmjs.com/package/node-fetch))

@@ -4,0 +6,0 @@ with sensible defaults for retrying to prevent common errors.

@@ -163,4 +163,4 @@ const assert = require('assert');

assert(err);
assert.equal(err.code, 'ERR_UNESCAPED_CHARACTERS');
assert.equal(err.message, 'Request path contains unescaped characters');
assert.equal(opts.onRetry.mock.calls.length, 0);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc