request-shim-for-callbacks
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "request-shim-for-callbacks", | ||
"description": "Wrap request's idiosyncratic callback format with a standard node-style callback", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"license" : "BSD-2-Clause", | ||
@@ -6,0 +6,0 @@ "main": "request-shim-for-callbacks.js", |
@@ -28,3 +28,4 @@ // Copyright (c) 2016, Body Labs, Inc. | ||
var _ = require('underscore'); | ||
var _ = require('underscore'), | ||
util = require('util'); | ||
@@ -43,6 +44,13 @@ // Wrap `request`'s idiosyncratic callback format with a standard Node-style | ||
} else if (response.statusCode != expectedStatusCode) { | ||
// When `body` is a string or undefined, `_.has` will return | ||
// `false`. | ||
var message = _(body).has('message') ? body.message : body; | ||
var message = | ||
util.format('%d%s%s', | ||
response.statusCode, | ||
(response.statusMessage || '') + ' ', | ||
// Use the `abody`'s message if is exists | ||
_(body).has('message') ? body.message : body || '' | ||
).trim(); | ||
callback(Error(message), null); | ||
@@ -49,0 +57,0 @@ } else { |
@@ -57,7 +57,7 @@ // Copyright (c) 2016, Body Labs, Inc. | ||
context('with an unexpected status, and no `message` property', function () { | ||
var errorObject = { foo: 'bar' }; | ||
var errorBody = JSON.stringify({ foo: 'bar' }); | ||
it('should return the entire body as the error', function (done) { | ||
var callback = verifyResponseStatus(200, function (err, response) { | ||
err.toString().should.equal('Error: ' + errorObject.toString()); | ||
err.toString().should.equal('Error: 400 ' + errorBody); | ||
@@ -69,3 +69,3 @@ done(); | ||
response = { statusCode: 400 }, | ||
body = errorObject; | ||
body = errorBody; | ||
@@ -77,7 +77,7 @@ callback(error, response, body); | ||
context('with an unexpected status, and a `message` property', function () { | ||
var errorObject = { message: 'This is the message' }; | ||
var errorBody = { message: 'This is the message' }; | ||
it('should return the message as the error', function (done) { | ||
var callback = verifyResponseStatus(200, function (err, response) { | ||
err.toString().should.equal('Error: ' + errorObject.message); | ||
err.toString().should.equal('Error: 400 ' + errorBody.message); | ||
@@ -89,3 +89,3 @@ done(); | ||
response = { statusCode: 400 }, | ||
body = errorObject; | ||
body = errorBody; | ||
@@ -103,3 +103,3 @@ callback(error, response, body); | ||
var callback = verifyResponseStatus(200, function (err, response) { | ||
err.toString().should.equal('Error: ' + html); | ||
err.toString().should.equal('Error: 500 ' + html); | ||
@@ -106,0 +106,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11333
152
1