{"pull_request":{"user":{"id":145951,"login":"kainosnoema","url":"https://api.github.com/users/kainosnoema","avatar_url":"https://secure.gravatar.com/avatar/15f514278e09962521274be4f59f727b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"15f514278e09962521274be4f59f727b"},"merged_at":"2011-12-21T16:13:53Z","created_at":"2011-12-16T17:13:07Z","title":"setAuth() should fail with error on non-204 response","updated_at":"2011-12-21T16:13:53Z","state":"closed","review_comments":0,"id":603703,"patch_url":"https://github.com/nodejitsu/node-cloudfiles/pull/25.patch","html_url":"https://github.com/nodejitsu/node-cloudfiles/pull/25","closed_at":"2011-12-21T16:13:53Z","deletions":1,"mergeable":null,"base":{"user":{"id":297492,"login":"nodejitsu","url":"https://api.github.com/users/nodejitsu","avatar_url":"https://secure.gravatar.com/avatar/5e06172730feb43518e532efc9c46a51?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"5e06172730feb43518e532efc9c46a51"},"ref":"master","sha":"a7062ea856dc5f8ab760ddb15322e6d1623def2f","repo":{"git_url":"git://github.com/nodejitsu/node-cloudfiles.git","created_at":"2010-09-08T04:27:40Z","watchers":80,"open_issues":10,"fork":false,"updated_at":"2011-12-21T16:13:54Z","id":895388,"language":"JavaScript","html_url":"https://github.com/nodejitsu/node-cloudfiles","name":"node-cloudfiles","description":"A client implementation for Rackspace CloudFIles in node.js","master_branch":null,"url":"https://api.github.com/repos/nodejitsu/node-cloudfiles","forks":20,"ssh_url":"git@github.com:nodejitsu/node-cloudfiles.git","clone_url":"https://github.com/nodejitsu/node-cloudfiles.git","pushed_at":"2011-12-21T16:13:53Z","owner":{"id":297492,"login":"nodejitsu","url":"https://api.github.com/users/nodejitsu","avatar_url":"https://secure.gravatar.com/avatar/5e06172730feb43518e532efc9c46a51?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"5e06172730feb43518e532efc9c46a51"},"homepage":"http://github.com/nodejitsu/node-cloudfiles","svn_url":"https://svn.github.com/nodejitsu/node-cloudfiles","size":224,"private":false},"label":"nodejitsu:master"},"issue_url":"https://github.com/nodejitsu/node-cloudfiles/issues/25","commits":1,"number":25,"body":"For some reason, when the request initiated by `setAuth()` returns a non-204 response (ie. 401 due to invalid api key, etc), no error is being returned and `authorized` is being set to true, even though all the config items (serverUrl, setStorageUrl, cdnUrl, etc) are undefined because of the unauthorized response. This leads to unexpected behavior since you're assuming you have authorization.\r\n\r\n[Relevant lines (lib/cloudfiles/core.js:62-75)](https://github.com/nodejitsu/node-cloudfiles/blob/master/lib/cloudfiles/core.js#L62-75):\r\n\r\n```` js\r\nrequest(authOptions, function (err, res, body) {\r\n  if (err) {\r\n    return callback(err); \r\n  }\r\n\r\n  self.authorized = true;\r\n  self.config.serverUrl = res.headers['x-server-management-url'];\r\n  self.config.setStorageUrl(res.headers['x-storage-url']);\r\n  self.config.cdnUrl = res.headers['x-cdn-management-url'];\r\n  self.config.authToken = res.headers['x-auth-token'];\r\n  self.config.storageToken = res.headers['x-storage-token']\r\n\r\n  callback(null, res, self.config);\r\n});\r\n````\r\n\r\nWe should probably also be checking that the res.statusCode is equal to 200, as per the [documentation for request] (https://github.com/mikeal/request):\r\n\r\n```` js\r\nvar request = require('request');\r\nrequest('http://www.google.com', function (error, response, body) {\r\n  if (!error && response.statusCode == 200) {\r\n    console.log(body) // Print the google web page.\r\n  }\r\n})\r\n````\r\n\r\n","additions":8,"url":"https://api.github.com/repos/nodejitsu/node-cloudfiles/pulls/25","_links":{"review_comments":{"href":"https://api.github.com/repos/nodejitsu/node-cloudfiles/pulls/25/comments"},"html":{"href":"https://github.com/nodejitsu/node-cloudfiles/pull/25"},"self":{"href":"https://api.github.com/repos/nodejitsu/node-cloudfiles/pulls/25"},"comments":{"href":"https://api.github.com/repos/nodejitsu/node-cloudfiles/issues/25/comments"}},"merged_by":{"id":234659,"login":"bmeck","url":"https://api.github.com/users/bmeck","avatar_url":"https://secure.gravatar.com/avatar/0b22453288cedbe28d53e89e0e0b793d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"0b22453288cedbe28d53e89e0e0b793d"},"diff_url":"https://github.com/nodejitsu/node-cloudfiles/pull/25.diff","comments":0,"head":{"user":{"id":145951,"login":"kainosnoema","url":"https://api.github.com/users/kainosnoema","avatar_url":"https://secure.gravatar.com/avatar/15f514278e09962521274be4f59f727b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"15f514278e09962521274be4f59f727b"},"ref":"fix/setAuth-error","sha":"c0da7403bfecb19041c11c1d8a4c89de00eb48ca","repo":{"git_url":"git://github.com/kainosnoema/node-cloudfiles.git","created_at":"2011-12-16T16:48:03Z","watchers":1,"open_issues":0,"fork":true,"updated_at":"2011-12-16T17:25:28Z","id":2996111,"language":"JavaScript","html_url":"https://github.com/kainosnoema/node-cloudfiles","name":"node-cloudfiles","description":"A client implementation for Rackspace CloudFIles in node.js","master_branch":null,"url":"https://api.github.com/repos/kainosnoema/node-cloudfiles","forks":0,"ssh_url":"git@github.com:kainosnoema/node-cloudfiles.git","clone_url":"https://github.com/kainosnoema/node-cloudfiles.git","pushed_at":"2011-12-16T17:25:28Z","owner":{"id":145951,"login":"kainosnoema","url":"https://api.github.com/users/kainosnoema","avatar_url":"https://secure.gravatar.com/avatar/15f514278e09962521274be4f59f727b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"15f514278e09962521274be4f59f727b"},"homepage":"http://github.com/nodejitsu/node-cloudfiles","svn_url":"https://svn.github.com/kainosnoema/node-cloudfiles","size":124,"private":false},"label":"kainosnoema:fix/setAuth-error"},"changed_files":2,"merged":true},"number":25,"action":"closed"}