Permalink
Browse files

setAuth() should fail with error on non-20x response

  • Loading branch information...
1 parent a7062ea commit c0da7403bfecb19041c11c1d8a4c89de00eb48ca @kainosnoema kainosnoema committed Dec 16, 2011
Showing with 8 additions and 1 deletion.
  1. +6 −0 lib/cloudfiles/core.js
  2. +2 −1 test/authentication-test.js
View
@@ -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']);
@@ -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);
}
},

0 comments on commit c0da740

Please sign in to comment.