From 6189e7a6dc8a65b66d80b0ee332a7382d49cd0fb Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Sun, 21 Feb 2016 20:43:13 +0100 Subject: [PATCH] Retry activation in case the we still get redirects --- cloudron.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cloudron.js b/cloudron.js index 73a781e..ee968ad 100644 --- a/cloudron.js +++ b/cloudron.js @@ -82,8 +82,22 @@ Cloudron.prototype.activate = function (user) { var setupToken = this._box.setupToken; ////////// activation - var res = request.post(this._origin + '/api/v1/cloudron/activate').query({ setupToken: setupToken }).send(user).end(); - common.verifyResponse2xx(res, 'Could not activate the box'); // 409 - already activated + var res; + for (var i = 0; i < 40; ++i) { + sleep(5); + + res = request.post(this._origin + '/api/v1/cloudron/activate').query({ setupToken: setupToken }).send(user).end(); + + if (res.statusCode === 201) break; + if (res.statusCode === 307) continue; + if (res.statusCode === 409) { + debug('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body); + throw new Error('Cloudron already activated! This should not happen'); + } + } + + // final verification will fail if retries do not succeed + common.verifyResponse2xx(res, 'Could not activate the box'); res = request.get(this._origin + '/api/v1/cloudron/status').end(); common.verifyResponse2xx(res, 'Could not get Cloudron status');