rest-facade
Advanced tools
Comparing version 1.10.1 to 1.10.2
{ | ||
"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'); |
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
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
51970
19
1181
+ Addedlodash.get@^4.4.2
+ Added@tootallnate/once@1.1.2(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedast-types@0.13.4(transitive)
+ Addeddata-uri-to-buffer@3.0.1(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addeddeepmerge@3.3.0(transitive)
+ Addeddegenerator@2.2.0(transitive)
+ Addedfile-uri-to-path@2.0.0(transitive)
+ Addedfs-extra@8.1.0(transitive)
+ Addedget-uri@3.0.2(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhttp-proxy-agent@4.0.1(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedip-address@9.0.5(transitive)
+ Addedjsbn@1.1.0(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedlodash.get@4.4.2(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addednetmask@2.0.2(transitive)
+ Addedpac-proxy-agent@4.1.0(transitive)
+ Addedpac-resolver@4.2.0(transitive)
+ Addedproxy-agent@4.0.1(transitive)
+ Addedsmart-buffer@4.2.0(transitive)
+ Addedsocks@2.8.3(transitive)
+ Addedsocks-proxy-agent@5.0.1(transitive)
+ Addedsprintf-js@1.1.3(transitive)
+ Addedsuperagent-proxy@2.1.0(transitive)
+ Addeduniversalify@0.1.2(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedbluebird@^2.10.2
- Removedagent-base@4.3.0(transitive)
- Removedast-types@0.16.1(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedco@4.6.0(transitive)
- Removeddata-uri-to-buffer@1.2.0(transitive)
- Removeddebug@2.6.93.1.0(transitive)
- Removeddeepmerge@1.5.2(transitive)
- Removeddegenerator@1.0.4(transitive)
- Removedes6-promise@4.2.8(transitive)
- Removedes6-promisify@5.0.0(transitive)
- Removedesprima@3.1.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedget-uri@2.0.4(transitive)
- Removedhttp-proxy-agent@2.1.0(transitive)
- Removedhttps-proxy-agent@2.2.4(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedms@2.0.0(transitive)
- Removednetmask@1.0.6(transitive)
- Removedpac-proxy-agent@2.0.2(transitive)
- Removedpac-resolver@3.0.0(transitive)
- Removedproxy-agent@2.3.1(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedsmart-buffer@1.1.15(transitive)
- Removedsocks@1.1.10(transitive)
- Removedsocks-proxy-agent@3.0.1(transitive)
- Removedsuperagent-proxy@1.0.3(transitive)
- Removedthunkify@2.1.2(transitive)
- Removedyallist@2.1.2(transitive)
Updateddeepmerge@^3.2.0
Updatedsuperagent@^3.8.3
Updatedsuperagent-proxy@^2.0.0