Skip to content

Commit

Permalink
setAuth() should fail with error on non-20x response
Browse files Browse the repository at this point in the history
  • Loading branch information
kainosnoema committed Dec 16, 2011
1 parent a7062ea commit c0da740
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/cloudfiles/core.js
Expand Up @@ -64,6 +64,12 @@ Cloudfiles.prototype.setAuth = function (callback) {
return callback(err);
}

var statusCode = res.statusCode.toString();
if (Object.keys(common.failCodes).indexOf(statusCode) !== -1) {
err = new Error('Rackspace Error (' + statusCode + '): ' + common.failCodes[statusCode]);
return callback(err, res);
}

self.authorized = true;
self.config.serverUrl = res.headers['x-server-management-url'];
self.config.setStorageUrl(res.headers['x-storage-url']);
Expand Down
3 changes: 2 additions & 1 deletion test/authentication-test.js
Expand Up @@ -46,7 +46,8 @@ vows.describe('node-cloudfiles/authentication').addBatch({

invalidClient.setAuth(this.callback);
},
"should respond with 401": function (err, res) {
"should respond with 401 and return an error": function (err, res) {
assert.ok(err instanceof Error);
assert.equal(res.statusCode, 401);
}
},
Expand Down

0 comments on commit c0da740

Please sign in to comment.