Socket
Socket
Sign inDemoInstall

superagent

Package Overview
Dependencies
Maintainers
10
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superagent - npm Package Compare versions

Comparing version 3.8.0-alpha.1 to 3.8.0

6

docs/index.md

@@ -214,4 +214,6 @@

When given the `.retry()` method, SuperAgent will automatically retry requests, if they fail in a way that is transient or could be due to a flaky Internet connection. `.retry()` takes an optional argument which is the maximum number of times to retry failed requests; the default is 3 times.
When given the `.retry()` method, SuperAgent will automatically retry requests, if they fail in a way that is transient or could be due to a flaky Internet connection.
This method has two optional arguments: number of retries (default 3) and a callback. It calls `callback(err, res)` before each retry. The callback may return `true`/`false` to control whether the request sould be retried (but the maximum number of retries is always applied).
request

@@ -222,2 +224,4 @@ .get('http://example.com/search')

Use `.retry()` only with requests that are *idempotent* (i.e. multiple requests reaching the server won't cause undesirable side effects like duplicate purchases).
## Setting Accept

@@ -224,0 +228,0 @@

@@ -0,1 +1,9 @@

# 3.8.0
* Added support for "globally" defined headers and event handlers via `superagent.agent()`. It now remembers default settings for all its requests.
* Added optional callback to `.retry()` (Alexander Murphy)
* Unified auth args handling in node/browser (Edmundo Alvarez)
* Fixed error handling in zlib pipes (Kornel)
* Documented that 3xx status codes are errors (Mickey Reiss)
# 3.7.0 (2017-10-17)

@@ -2,0 +10,0 @@

4

lib/client.js

@@ -20,3 +20,2 @@ /**

var Agent = require('./agent-base');
var shouldRetry = require('./should-retry');

@@ -599,4 +598,3 @@ /**

Request.prototype.callback = function(err, res){
// console.log(this._retries, this._maxRetries)
if (this._maxRetries && this._retries++ < this._maxRetries && shouldRetry(err, res)) {
if (this._shouldRetry(err, res)) {
return this._retry();

@@ -603,0 +601,0 @@ }

@@ -28,3 +28,2 @@ 'use strict';

const RequestBase = require('../request-base');
const shouldRetry = require('../should-retry');

@@ -681,4 +680,3 @@ function request(method, url) {

Request.prototype.callback = function(err, res){
// console.log(this._retries, this._maxRetries)
if (this._maxRetries && this._retries++ < this._maxRetries && shouldRetry(err, res)) {
if (this._shouldRetry(err, res)) {
return this._retry();

@@ -685,0 +683,0 @@ }

@@ -146,2 +146,3 @@ 'use strict';

* @param {Number} count
* @param {Function} [fn]
* @return {Request} for chaining

@@ -151,3 +152,3 @@ * @api public

RequestBase.prototype.retry = function retry(count){
RequestBase.prototype.retry = function retry(count, fn){
// Default to 1 if no count passed or true

@@ -158,6 +159,46 @@ if (arguments.length === 0 || count === true) count = 1;

this._retries = 0;
this._retryCallback = fn;
return this;
};
var ERROR_CODES = [
'ECONNRESET',
'ETIMEDOUT',
'EADDRINFO',
'ESOCKETTIMEDOUT'
];
/**
* Determine if a request should be retried.
* (Borrowed from segmentio/superagent-retry)
*
* @param {Error} err
* @param {Response} [res]
* @returns {Boolean}
*/
RequestBase.prototype._shouldRetry = function(err, res) {
if (!this._maxRetries || this._retries++ >= this._maxRetries) {
return false;
}
if (this._retryCallback) {
try {
var override = this._retryCallback(err, res);
if (override === true) return true;
if (override === false) return false;
// undefined falls back to defaults
} catch(e) {
console.error(e);
}
}
if (res && res.status && res.status >= 500 && res.status != 501) return true;
if (err) {
if (err.code && ~ERROR_CODES.indexOf(err.code)) return true;
// Superagent timeout
if (err.timeout && err.code == 'ECONNABORTED') return true;
if (err.crossDomain) return true;
}
return false;
};
/**
* Retry request

@@ -170,2 +211,3 @@ *

RequestBase.prototype._retry = function() {
this.clearTimeout();

@@ -172,0 +214,0 @@

{
"name": "superagent",
"version": "3.8.0-alpha.1",
"version": "3.8.0",
"description": "elegant & feature rich browser / node HTTP with a fluent API",

@@ -5,0 +5,0 @@ "scripts": {

@@ -186,2 +186,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.superagent = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

* @param {Number} count
* @param {Function} [fn]
* @return {Request} for chaining

@@ -191,3 +192,3 @@ * @api public

RequestBase.prototype.retry = function retry(count){
RequestBase.prototype.retry = function retry(count, fn){
// Default to 1 if no count passed or true

@@ -198,6 +199,46 @@ if (arguments.length === 0 || count === true) count = 1;

this._retries = 0;
this._retryCallback = fn;
return this;
};
var ERROR_CODES = [
'ECONNRESET',
'ETIMEDOUT',
'EADDRINFO',
'ESOCKETTIMEDOUT'
];
/**
* Determine if a request should be retried.
* (Borrowed from segmentio/superagent-retry)
*
* @param {Error} err
* @param {Response} [res]
* @returns {Boolean}
*/
RequestBase.prototype._shouldRetry = function(err, res) {
if (!this._maxRetries || this._retries++ >= this._maxRetries) {
return false;
}
if (this._retryCallback) {
try {
var override = this._retryCallback(err, res);
if (override === true) return true;
if (override === false) return false;
// undefined falls back to defaults
} catch(e) {
console.error(e);
}
}
if (res && res.status && res.status >= 500 && res.status != 501) return true;
if (err) {
if (err.code && ~ERROR_CODES.indexOf(err.code)) return true;
// Superagent timeout
if (err.timeout && err.code == 'ECONNABORTED') return true;
if (err.crossDomain) return true;
}
return false;
};
/**
* Retry request

@@ -210,2 +251,3 @@ *

RequestBase.prototype._retry = function() {
this.clearTimeout();

@@ -834,33 +876,6 @@

},{"./utils":6}],5:[function(require,module,exports){
},{"./utils":5}],5:[function(require,module,exports){
'use strict';
var ERROR_CODES = [
'ECONNRESET',
'ETIMEDOUT',
'EADDRINFO',
'ESOCKETTIMEDOUT'
];
/**
* Determine if a request should be retried.
* (Borrowed from segmentio/superagent-retry)
*
* @param {Error} err
* @param {Response} [res]
* @returns {Boolean}
*/
module.exports = function shouldRetry(err, res) {
if (err && err.code && ~ERROR_CODES.indexOf(err.code)) return true;
if (res && res.status && res.status >= 500) return true;
// Superagent timeout
if (err && 'timeout' in err && err.code == 'ECONNABORTED') return true;
if (err && 'crossDomain' in err) return true;
return false;
};
},{}],6:[function(require,module,exports){
'use strict';
/**
* Return the mime type for the given `str`.

@@ -933,3 +948,3 @@ *

},{}],7:[function(require,module,exports){
},{}],6:[function(require,module,exports){

@@ -1099,3 +1114,3 @@ /**

},{}],8:[function(require,module,exports){
},{}],7:[function(require,module,exports){
/**

@@ -1120,3 +1135,2 @@ * Root reference for iframes.

var Agent = require('./agent-base');
var shouldRetry = require('./should-retry');

@@ -1699,4 +1713,3 @@ /**

Request.prototype.callback = function(err, res){
// console.log(this._retries, this._maxRetries)
if (this._maxRetries && this._retries++ < this._maxRetries && shouldRetry(err, res)) {
if (this._shouldRetry(err, res)) {
return this._retry();

@@ -2024,3 +2037,3 @@ }

},{"./agent-base":1,"./is-object":2,"./request-base":3,"./response-base":4,"./should-retry":5,"component-emitter":7}]},{},[8])(8)
},{"./agent-base":1,"./is-object":2,"./request-base":3,"./response-base":4,"component-emitter":6}]},{},[7])(7)
});
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