diff --git a/lib/cloudfiles/core.js b/lib/cloudfiles/core.js index 3fe3abe..4b7101a 100644 --- a/lib/cloudfiles/core.js +++ b/lib/cloudfiles/core.js @@ -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']); diff --git a/test/authentication-test.js b/test/authentication-test.js index aa99a98..47c74bf 100644 --- a/test/authentication-test.js +++ b/test/authentication-test.js @@ -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); } },