Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/cloudcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,18 @@ Cloudcontrol.prototype.curl = function curl(options, cb) {
})

url = self.protocol + '://' + self.host + options.path
if (options.params) url += '?'

if (typeof options.params === 'string') url += options.params
if (typeof options.params === 'object') Object.keys(options.params).forEach(function(key) {
url += key + '=' + escape(options.params[key])
})
if (options.params && options.method === 'POST') {
var curlified = Object.keys(options.params).map(function (key) { return '-d ' + key + '=' + options.params[key]; });
cmd += ' ' + curlified.join(' ');
} else if (options.params) {
if (options.params) url += '?'

if (typeof options.params === 'string') url += options.params
if (typeof options.params === 'object') Object.keys(options.params).forEach(function(key) {
url += key + '=' + escape(options.params[key])
})
}
cmd += ' "' + url + '"'
exec(cmd, function(err, result) {
cb(err, result)
Expand Down Expand Up @@ -186,7 +192,7 @@ Cloudcontrol.prototype.request = function request(options, cb) {
try {
result = JSON.parse(result)
} catch(e) {
if (result === "Authorization Required") {
if (result === "Authorization Required" || result === "Unauthorized") {
self.retries++
if (self.retries < 3) {
// try to reauthenticate
Expand Down