Skip to content

Commit

Permalink
Handle single error responses from AWS.
Browse files Browse the repository at this point in the history
The result object can either have `Error` or `Errors` depending on the
service or the number of errors generated.

Refs livelycode/aws-lib/issues#42
  • Loading branch information
willwhite committed Feb 21, 2013
1 parent b3ed99e commit 71fd7e0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/aws.js
Expand Up @@ -118,10 +118,15 @@ var genericAWSClient = function(obj) {
res.addListener('end', function() {
var parser = new xml2js.Parser();
parser.addListener('end', function(result) {
if (typeof result != "undefined" && typeof result.Errors != "undefined"){
callback(new Error(result.Errors.Error.Message), result)
if (typeof result != "undefined") {
var err = result.Error || (result.Errors ? result.Errors.Error : null)
if (err) {
callback(new Error(err.Message), result)
} else {
callback(null, result)
}
} else {
callback(null, result)
callback(new Error('Unable to parse XML from AWS.'))
}
});
parser.parseString(data);
Expand Down

0 comments on commit 71fd7e0

Please sign in to comment.