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

rest-facade

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-facade - npm Package Compare versions

Comparing version 1.10.1 to 1.10.2

tests/utils.tests.js

12

package.json
{
"name": "rest-facade",
"version": "1.10.1",
"version": "1.10.2",
"description": "Simple abstraction for consuming REST API endpoints",

@@ -32,3 +32,3 @@ "main": "src/index.js",

"chai": "^3.4.0",
"coveralls": "^2.11.4",
"coveralls": "^2.13.3",
"mocha": "^2.3.3",

@@ -40,8 +40,8 @@ "mocha-lcov-reporter": "^1.0.0",

"dependencies": {
"bluebird": "^2.10.2",
"change-case": "^2.3.0",
"deepmerge": "^1.5.1",
"superagent": "^3.8.0",
"superagent-proxy": "^1.0.2"
"deepmerge": "^3.2.0",
"lodash.get": "^4.4.2",
"superagent": "^3.8.3",
"superagent-proxy": "^2.0.0"
}
}

@@ -8,7 +8,6 @@ var extend = require('util')._extend;

var request = require('superagent');
var Promise = require('bluebird');
var ArgumentError = require('./exceptions').ArgumentError;
var APIError = require('./exceptions').APIError;
var defaultOptions = require('./defaultOptions');
var goToPath = require('./utils').goToPath;
var resolveAPIErrorArg = require('./utils').resolveAPIErrorArg;
var isFunction = require('./utils').isFunction;

@@ -31,3 +30,3 @@

this.options = deepmerge(defaultOptions, options || {}, true);
this.options = deepmerge(defaultOptions, options || {});

@@ -273,3 +272,3 @@ this.url = url.parse(resourceUrl);

var headers = this.options.headers || {};
var errorFormatter = this.options.errorFormatter || null;
var errorFormatter = this.options.errorFormatter || {};
var paramsCase = this.options.query.convertCase;

@@ -357,12 +356,6 @@ var bodyCase = this.options.request.body.convertCase;

if (errorFormatter && errorFormatter.hasOwnProperty('name') &&
errorFormatter.hasOwnProperty('message')) {
var name = goToPath(errorFormatter.name, data);
var message = data ? goToPath(errorFormatter.message, data) : err.message;
error = new APIError(name, message, status, reqinfo, err);
} else {
error = new APIError('APIError', data ? JSON.stringify(data) : err.message, status, reqinfo, err);
}
var name = resolveAPIErrorArg(errorFormatter.name, data, 'APIError');
var message = resolveAPIErrorArg(errorFormatter.message, data, [data, err.message]);
return reject(error);
return reject(new APIError(name, message, status, reqinfo, err))
}

@@ -369,0 +362,0 @@

@@ -6,21 +6,44 @@ var objectProto = Object.prototype;

var get = require('lodash.get');
/*
* Auxiliar function for get the error attributes
* from the given path.
* Auxiliar function for extracting an APIError argument from the
* given `data` using the given "formatter"
*
* @param {String|Function|undefined) formatter - either a string used to "get" the property-path,
* or a custom function (data is passed to it)
* @param {Object|null} data - a data object, assumed to be the response body
* @param {mixed|Array[mixed]) defaults - a default value, or an array of defaults values.
* used if no value could be extracted from `data` using the `formatter`
* (e.g. if data is empty or the formatter is undefined),
* in the case of multiple defaults the first TRUTHY value is used.
*
* @return {String}
*/
function goToPath(path, obj) {
var current = obj;
var keys = path.split('.');
var currentKey;
function resolveAPIErrorArg(formatter, data, defaults)
{
var val, def;
var defs = Array.isArray(defaults) ? defaults : [defaults];
while (currentKey = keys.shift()) {
if (typeof current === 'object' &&
current.hasOwnProperty(currentKey)) {
current = current[currentKey];
}
if (formatter && data) {
switch (typeof formatter) {
case 'function':
val = formatter(data);
break;
case 'string':
val = get(data, formatter);
break;
}
}
return current;
};
while (!val && defs.length) {
val = defs.shift();
}
if (val && (typeof val === 'object'))
val = JSON.stringify(val);
return (val || '') + '';
}
/**

@@ -85,5 +108,5 @@ * N.B. baseGetTag(), isObject() & isFunction() are lifted straight out of Lodash,

module.exports = {
goToPath : goToPath,
resolveAPIErrorArg : resolveAPIErrorArg,
isObject : isObject,
isFunction : isFunction
};

@@ -7,3 +7,2 @@ var extend = require('util')._extend;

var http = require('http');
var Promise = require('bluebird');

@@ -10,0 +9,0 @@ var Client = require('../src/Client');

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