got
Advanced tools
Comparing version 2.5.0 to 2.6.0
26
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
var urlLib = require('url'); | ||
var util = require('util'); | ||
var zlib = require('zlib'); | ||
@@ -16,3 +17,12 @@ var objectAssign = require('object-assign'); | ||
var status = require('statuses'); | ||
var NestedError = require('nested-error-stacks'); | ||
function GotError(message, nested) { | ||
NestedError.call(this, message, nested); | ||
objectAssign(this, nested); | ||
} | ||
util.inherits(GotError, NestedError); | ||
GotError.prototype.name = 'GotError'; | ||
function got(url, opts, cb) { | ||
@@ -79,3 +89,3 @@ if (typeof opts === 'function') { | ||
if (++redirectCount > 10) { | ||
cb(new Error('Redirected 10 times. Aborting.'), undefined, res); | ||
cb(new GotError('Redirected 10 times. Aborting.'), undefined, res); | ||
return; | ||
@@ -95,4 +105,4 @@ } | ||
if (statusCode < 200 || statusCode > 299) { | ||
read(res, encoding, function (error, data) { | ||
var err = error || new Error(url + ' response code is ' + statusCode + ' (' + status[statusCode] + ')'); | ||
read(res, encoding, function (err, data) { | ||
err = new GotError(url + ' response code is ' + statusCode + ' (' + status[statusCode] + ')', err); | ||
err.code = statusCode; | ||
@@ -111,5 +121,11 @@ cb(err, data, response); | ||
read(res, encoding, function (err, data) { | ||
cb.call(null, err, data, response); | ||
if (err) { | ||
err = new GotError('Reading ' + url + ' response failed', err); | ||
} | ||
cb(err, data, response); | ||
}); | ||
}).once('error', cb); | ||
}).once('error', function (err) { | ||
cb(new GotError('Request to ' + url + ' failed', err)); | ||
}); | ||
@@ -116,0 +132,0 @@ if (opts.timeout) { |
{ | ||
"name": "got", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "Simplified HTTP/HTTPS requests", | ||
@@ -23,3 +23,4 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "taper test/test-*.js" | ||
"test": "tape test/test-*.js | tap-dot", | ||
"coverage": "istanbul cover tape --report html -- test/test-*.js" | ||
}, | ||
@@ -46,5 +47,6 @@ "files": [ | ||
"lowercase-keys": "^1.0.0", | ||
"nested-error-stacks": "^1.0.0", | ||
"object-assign": "^2.0.0", | ||
"prepend-http": "^1.0.0", | ||
"read-all-stream": "^1.0.0", | ||
"read-all-stream": "^2.0.0", | ||
"statuses": "^1.2.1", | ||
@@ -55,6 +57,7 @@ "timed-out": "^2.0.0" | ||
"from2-array": "0.0.3", | ||
"istanbul": "^0.3.13", | ||
"pem": "^1.4.4", | ||
"tape": "^3.0.3", | ||
"taper": "^0.3.0" | ||
"tap-dot": "^1.0.0", | ||
"tape": "^3.5.0" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9135
149
2
10
5
+ Addednested-error-stacks@^1.0.0
+ Addednested-error-stacks@1.0.2(transitive)
+ Addedread-all-stream@2.2.0(transitive)
- Removedread-all-stream@1.0.2(transitive)
Updatedread-all-stream@^2.0.0