http-as-promised
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -45,2 +45,3 @@ var createError = require('create-error'), | ||
HTTPError[0] = HTTPError; | ||
HTTPError.prototype.toJSON = errorToJSON; | ||
@@ -47,0 +48,0 @@ |
@@ -26,5 +26,10 @@ var Promise = require('bluebird'), | ||
HTTP.error = require('./http.error'); | ||
HTTP.defaults = setDefaults; | ||
Object.defineProperties(HTTP, { | ||
error: { | ||
value: require('./http.error'), | ||
enumerable: false, | ||
configurable: false, | ||
writable: false | ||
}, | ||
request: { | ||
@@ -69,6 +74,20 @@ value: request, | ||
reject(httpErr); | ||
} else if (typeof opts.transform === 'function') { | ||
resolve([response, opts.transform(response, body)]); | ||
} else { | ||
resolve([response, body]); | ||
if (typeof opts.transform === 'function') { | ||
body = opts.transform(response, body); | ||
} | ||
if (!opts.resolve) { | ||
resolve([response, body]); | ||
} else if (opts.resolve === 'body') { | ||
resolve(body); | ||
} else if (opts.resolve === 'response') { | ||
resolve(response); | ||
} else if (Array.isArray(opts.resolve) | ||
&& opts.resolve.length === 2 | ||
&& opts.resolve[0] === 'body' | ||
&& opts.resolve[1] === 'response') { | ||
resolve([body, response]); | ||
} else { | ||
resolve([response, body]); | ||
} | ||
} | ||
@@ -75,0 +94,0 @@ }); |
@@ -6,3 +6,3 @@ { | ||
"main": "http.promise.js", | ||
"tags": [ | ||
"keywords": [ | ||
"errors", | ||
@@ -21,3 +21,3 @@ "exceptions", | ||
], | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"author": "James Cready <jcready@gmail.com> (http://stackoverflow.com/users/1397319/idbehold)", | ||
@@ -49,3 +49,2 @@ "homepage": "https://github.com/jcready/http-as-promised", | ||
"chai-as-promised": "^4.1.1", | ||
"chance": "^0.6.1", | ||
"coveralls": "^2.11.1", | ||
@@ -52,0 +51,0 @@ "istanbul": "^0.3.2", |
17461
9
379