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

stubborn-fetch

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stubborn-fetch - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

70

dist/index.es.js

@@ -558,20 +558,72 @@ (function(self) {

};
var persistResponse = function persistResponse(response) {
return {
headers: response.headers,
ok: response.ok,
redirected: response.redirected,
status: response.status,
statusText: response.statusText,
type: response.type,
url: response.url,
bodyUsed: response.bodyUsed
};
};
var generateResponseObject = function generateResponseObject(statusText, url) {
return {
headers: {},
ok: false,
redirected: undefined,
status: 0,
statusText: statusText,
type: 'error',
url: url,
bodyUsed: false
};
};
var ErrorFactory = {
TIMEOUT: function TIMEOUT(url, request) {
return new StubbornFetchError(StubbornFetchError.types.TIMEOUT, { url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.TIMEOUT, {
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.TIMEOUT, url)
});
},
MAX_ERRORS_EXCEEDED: function MAX_ERRORS_EXCEEDED(url, request, errorLimit) {
return new StubbornFetchError('Max_Errors_Exceeded', { errorLimit: errorLimit, url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.MAX_ERROS_EXCEEDED, {
errorLimit: errorLimit,
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.MAX_ERROS_EXCEEDED, url)
});
},
NETWORK_ERROR: function NETWORK_ERROR(url, request, underlyingError) {
return new StubbornFetchError('Network', { underlyingError: underlyingError, url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.NETWORK_ERROR, {
underlyingError: underlyingError,
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.NETWORK_ERROR, url)
});
},
STUBBORN_FETCH_DISABLED: function STUBBORN_FETCH_DISABLED(url, request) {
return new StubbornFetchError('Stubborn_Fetch_Disabled', { url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.STUBBORN_FETCH_DISABLED, {
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.STUBBORN_FETCH_DISABLED, url)
});
},
HTTP_ERROR: function HTTP_ERROR(url, request, response) {
return new StubbornFetchError('HTTP', { response: response, url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.HTTP_ERROR, {
url: url,
request: request,
response: persistResponse(response)
});
},
RATE_LIMITED: function RATE_LIMITED(url, request) {
return new StubbornFetchError('Rate_Limited', { url: url, request: request });
RATE_LIMITED: function RATE_LIMITED(url, request, response) {
return new StubbornFetchError(StubbornFetchError.types.RATE_LIMITED, {
url: url,
request: request,
response: persistResponse(response)
});
}

@@ -757,4 +809,4 @@ };

// Does this push us beyond the time limit?
if (this.options.totalRequestTimeLimit && StubbornFetchRequest.rateLimitedUntil - this.startTime > this.options.totalRequestTimeLimit) {
this.error = ErrorFactory.RATE_LIMITED(this.url, this.fetchRequest);
if (this.options.totalRequestTimeLimit && StubbornFetchRequest.rateLimitedUntil - this.startTime > this.options.totalRequestTimeLimit && e.data.response) {
this.error = ErrorFactory.RATE_LIMITED(this.url, this.fetchRequest, e.data.response);
this.rejectImmediately(this.error);

@@ -761,0 +813,0 @@ }

@@ -562,20 +562,72 @@ 'use strict';

};
var persistResponse = function persistResponse(response) {
return {
headers: response.headers,
ok: response.ok,
redirected: response.redirected,
status: response.status,
statusText: response.statusText,
type: response.type,
url: response.url,
bodyUsed: response.bodyUsed
};
};
var generateResponseObject = function generateResponseObject(statusText, url) {
return {
headers: {},
ok: false,
redirected: undefined,
status: 0,
statusText: statusText,
type: 'error',
url: url,
bodyUsed: false
};
};
var ErrorFactory = {
TIMEOUT: function TIMEOUT(url, request) {
return new StubbornFetchError(StubbornFetchError.types.TIMEOUT, { url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.TIMEOUT, {
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.TIMEOUT, url)
});
},
MAX_ERRORS_EXCEEDED: function MAX_ERRORS_EXCEEDED(url, request, errorLimit) {
return new StubbornFetchError('Max_Errors_Exceeded', { errorLimit: errorLimit, url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.MAX_ERROS_EXCEEDED, {
errorLimit: errorLimit,
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.MAX_ERROS_EXCEEDED, url)
});
},
NETWORK_ERROR: function NETWORK_ERROR(url, request, underlyingError) {
return new StubbornFetchError('Network', { underlyingError: underlyingError, url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.NETWORK_ERROR, {
underlyingError: underlyingError,
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.NETWORK_ERROR, url)
});
},
STUBBORN_FETCH_DISABLED: function STUBBORN_FETCH_DISABLED(url, request) {
return new StubbornFetchError('Stubborn_Fetch_Disabled', { url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.STUBBORN_FETCH_DISABLED, {
url: url,
request: request,
response: generateResponseObject(StubbornFetchError.types.STUBBORN_FETCH_DISABLED, url)
});
},
HTTP_ERROR: function HTTP_ERROR(url, request, response) {
return new StubbornFetchError('HTTP', { response: response, url: url, request: request });
return new StubbornFetchError(StubbornFetchError.types.HTTP_ERROR, {
url: url,
request: request,
response: persistResponse(response)
});
},
RATE_LIMITED: function RATE_LIMITED(url, request) {
return new StubbornFetchError('Rate_Limited', { url: url, request: request });
RATE_LIMITED: function RATE_LIMITED(url, request, response) {
return new StubbornFetchError(StubbornFetchError.types.RATE_LIMITED, {
url: url,
request: request,
response: persistResponse(response)
});
}

@@ -761,4 +813,4 @@ };

// Does this push us beyond the time limit?
if (this.options.totalRequestTimeLimit && StubbornFetchRequest.rateLimitedUntil - this.startTime > this.options.totalRequestTimeLimit) {
this.error = ErrorFactory.RATE_LIMITED(this.url, this.fetchRequest);
if (this.options.totalRequestTimeLimit && StubbornFetchRequest.rateLimitedUntil - this.startTime > this.options.totalRequestTimeLimit && e.data.response) {
this.error = ErrorFactory.RATE_LIMITED(this.url, this.fetchRequest, e.data.response);
this.rejectImmediately(this.error);

@@ -765,0 +817,0 @@ }

28

package.json
{
"name": "stubborn-fetch",
"version": "0.1.0",
"version": "0.2.0",
"description": "Fetch wrapper with built in retry",

@@ -15,10 +15,8 @@ "main": "dist/index.js",

"prepublish": "npm run build",
"test": "./node_modules/.bin/flow && ./node_modules/.bin/jest && node ./node_modules/eslint/bin/eslint.js src/ --quiet",
"test":
"./node_modules/.bin/flow && ./node_modules/.bin/jest && node ./node_modules/eslint/bin/eslint.js src/ --quiet",
"precommit": "lint-staged"
},
"lint-staged": {
"src/**/*.js": [
"./node_modules/.bin/prettier --write",
"git add"
]
"src/**/*.js": ["./node_modules/.bin/prettier --write", "git add"]
},

@@ -30,19 +28,11 @@ "pre-commit": "lint-staged",

},
"keywords": [
"fetch",
"retry"
],
"keywords": ["fetch", "retry"],
"author": "Quiq",
"license": "MIT",
"jest": {
"moduleDirectories": [
"src",
"node_modules"
],
"moduleDirectories": ["src", "node_modules"],
"testEnvironmentOptions": {
"resources": "usable"
},
"setupFiles": [
"./jest.setup.js"
]
"setupFiles": ["./jest.setup.js"]
},

@@ -85,5 +75,3 @@ "bugs": {

},
"files": [
"dist"
]
"files": ["dist"]
}
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