Comparing version 0.8.10 to 0.8.11
@@ -0,1 +1,4 @@ | ||
## v0.8.11 | ||
* Added more robust error handling for openstack.identity admin methods | ||
## v0.8.10 | ||
@@ -2,0 +5,0 @@ * Fixing a bug in rackspace.dns where status call can be an empty response |
@@ -17,4 +17,19 @@ /* | ||
util = require('util'), | ||
pkgcloud = require('../../../pkgcloud'); | ||
pkgcloud = require('../../../pkgcloud'), | ||
errs = require('errs'); | ||
// TODO refactor failCodes, getError into global handlers | ||
var failCodes = { | ||
400: 'Bad Request', | ||
401: 'Unauthorized', | ||
403: 'Resize not allowed', | ||
404: 'Item not found', | ||
405: 'Bad Method', | ||
409: 'Build in progress', | ||
413: 'Over Limit', | ||
415: 'Bad Media Type', | ||
500: 'Fault', | ||
503: 'Service Unavailable' | ||
}; | ||
/** | ||
@@ -308,7 +323,7 @@ * exports.createIdentity | ||
request(options, function(err, res, body) { | ||
return err | ||
? callback(err) | ||
: (res.statusCode === 200 | ||
? callback(err, true, body) | ||
: callback(err, false)); | ||
var error = getError(err, res, body); | ||
return error | ||
? callback(error) | ||
: callback(error, body); | ||
}); | ||
@@ -366,9 +381,39 @@ } | ||
request(options, function(err, res, body) { | ||
return err | ||
? callback(err) | ||
: (res.statusCode === 200 | ||
? callback(err, body) | ||
: callback(err)); | ||
return callback(getError(err, res, body)); | ||
}); | ||
} | ||
}; | ||
function getError(err, res, body) { | ||
if (err) { | ||
return err; | ||
} | ||
var statusCode = res.statusCode.toString(), | ||
err2; | ||
if (Object.keys(failCodes).indexOf(statusCode) !== -1) { | ||
// | ||
// TODO: Support more than JSON errors here | ||
// | ||
err2 = { | ||
failCode: failCodes[statusCode], | ||
statusCode: res.statusCode, | ||
message: 'Error (' + | ||
statusCode + '): ' + failCodes[statusCode], | ||
href: res.request.uri.href, | ||
method: res.request.method, | ||
headers: res.headers | ||
}; | ||
try { | ||
err2.result = typeof body === 'string' ? JSON.parse(body) : body; | ||
} catch (e) { | ||
err2.result = { err: body }; | ||
} | ||
return err2; | ||
} | ||
return; | ||
} |
{ | ||
"name": "pkgcloud", | ||
"description": "An infrastructure-as-a-service agnostic cloud library for node.js", | ||
"version": "0.8.10", | ||
"version": "0.8.11", | ||
"author": "Nodejitsu Inc <info@nodejitsu.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
Sorry, the diff of this file is not supported yet
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
664085
14661