Skip to content

Commit

Permalink
[fix] Defensively program against unknown providers and datacenters.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Feb 6, 2013
1 parent bd283e5 commit cf4d2ae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions node.js/lib/client/client.js
Expand Up @@ -109,16 +109,24 @@ Client.prototype.cloud = function (options, api, callback) {
return memo;
}, {});

if (!self.datacenters || !self.datacenters[cloud.provider]
|| self.datacenters[cloud.provider][cloud.datacenter]) {
return done(new Error('Unknown cloud: ' + cloud.provider + ' ' + cloud.datacenter));
}

opts.remoteUri = self.datacenters[cloud.provider][cloud.datacenter];
if (!~opts.remoteUri.indexOf('http')) opts.remoteUri = 'https://'+ opts.remoteUri;

api.call(self, opts, done);
}, function ready(err, results) {
if (err) delete self.clouds[options.appName];
if (err) {
delete self.clouds[options.appName];
return callback(err);
}

return results.length === 1
? callback(err, results[0])
: callback(err, results)
? callback(null, results[0])
: callback(null, results)

//
// We probably want to figure out which calls went okay, and which one
Expand Down

0 comments on commit cf4d2ae

Please sign in to comment.