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

request-shim-for-callbacks

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-shim-for-callbacks - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

package.json
{
"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();

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