superagent 4.1.0-beta.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/History.md CHANGED
@@ -1,9 +1,10 @@
1
- # 4.1.0-beta (2018-12-02)
1
+ # 4.1.0 (2018-12-26)
2
2
 
3
3
  * `.connect()` IP/DNS override option (Kornel)
4
4
  * `.trustLocalhost()` option for allowing broken HTTPS on `localhost`
5
+ * `.abort()` used with promises rejects the promise.
5
6
 
6
- # 4.0.0 (2018-11-17)
7
+ # 4.0.0 (2018-11-17)
7
8
 
8
9
  ## Breaking changes
9
10
 
@@ -236,6 +236,14 @@ RequestBase.prototype.then = function then(resolve, reject) {
236
236
  }
237
237
  this._fullfilledPromise = new Promise((innerResolve, innerReject) => {
238
238
  self.on('error', innerReject);
239
+ self.on('abort', () => {
240
+ const err = new Error('Aborted');
241
+ err.code = "ABORTED";
242
+ err.status = this.status;
243
+ err.method = this.method;
244
+ err.url = this.url;
245
+ innerReject(err);
246
+ });
239
247
  self.end((err, res) => {
240
248
  if (err) innerReject(err);
241
249
  else innerResolve(res);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superagent",
3
- "version": "4.1.0-beta.1",
3
+ "version": "4.1.0",
4
4
  "description": "elegant & feature rich browser / node HTTP with a fluent API",
5
5
  "scripts": {
6
6
  "prepare": "make all",
package/superagent.js CHANGED
@@ -274,6 +274,8 @@ RequestBase.prototype._retry = function () {
274
274
  */
275
275
 
276
276
  RequestBase.prototype.then = function then(resolve, reject) {
277
+ var _this = this;
278
+
277
279
  if (!this._fullfilledPromise) {
278
280
  var self = this;
279
281
  if (this._endCalled) {
@@ -281,6 +283,14 @@ RequestBase.prototype.then = function then(resolve, reject) {
281
283
  }
282
284
  this._fullfilledPromise = new Promise(function (innerResolve, innerReject) {
283
285
  self.on('error', innerReject);
286
+ self.on('abort', function () {
287
+ var err = new Error('Aborted');
288
+ err.code = "ABORTED";
289
+ err.status = _this.status;
290
+ err.method = _this.method;
291
+ err.url = _this.url;
292
+ innerReject(err);
293
+ });
284
294
  self.end(function (err, res) {
285
295
  if (err) innerReject(err);else innerResolve(res);
286
296
  });