From 5e679a256feca5230572f46e284651103a049bf6 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 29 Sep 2015 13:25:09 -0700 Subject: [PATCH] print cloudron info if box creation failed --- appstore.js | 2 +- common.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/appstore.js b/appstore.js index 90fde5c..b875a4f 100644 --- a/appstore.js +++ b/appstore.js @@ -74,7 +74,7 @@ AppStore.prototype.waitForCloudron = function (boxId) { AppStore.prototype.createCloudron = function (box) { var accessToken = this._credentials.accessToken; var res = request.post(this._origin + '/api/v1/cloudrons').send(box).query({ accessToken: accessToken }).end(); - common.verifyResponse(res, 'Could not create cloudron'); + common.verifyResponse(res, 'Could not create cloudron %j', box); debug('Cloudron %s created'.green, box.domain); return res.body.box; diff --git a/common.js b/common.js index 5defc8d..5c340e8 100644 --- a/common.js +++ b/common.js @@ -2,6 +2,7 @@ var path = require('path'), safe = require('safetydance'), + util = require('util'), _ = require('underscore'); exports = module.exports = { @@ -37,18 +38,20 @@ function stripUnreachable(releases) { return _.pick(releases, reachableVersions); } -function verifyResponse2(res, errorMessage) { +function verifyResponse2(res, args) { if (res.statusCode < 200 || res.statusCode > 399) { debug('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body); + var errorMessage = util.format.apply(util, Array.prototype.slice.call(arguments, 1)); debug(errorMessage.red); throw new Error(errorMessage); } } -function verifyResponse(res, errorMessage) { +function verifyResponse(res, args) { if (res.statusCode < 200 || res.statusCode > 299) { console.log('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body); - console.log(errorMessage.red); + var errorMessage = util.format.apply(util, Array.prototype.slice.call(arguments, 1)); + debug(errorMessage.red); process.exit(1); } }