Use common.verifyResponse
This commit is contained in:
parent
6b06bca675
commit
9e23339346
22
appstore.js
22
appstore.js
@ -18,17 +18,9 @@ function AppStore(origin) {
|
||||
};
|
||||
}
|
||||
|
||||
function verifyResponse(res, errorMessage) {
|
||||
if (res.statusCode < 200 || res.statusCode > 299) {
|
||||
debug('Response error statusCode:%s error:%s body:%j', res.statusCode, res.error, res.body);
|
||||
debug(errorMessage.red);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
AppStore.prototype.getAccessToken = function (user) {
|
||||
var res = request.get(this._origin + '/api/v1/login').auth(user.email, user.password).end();
|
||||
verifyResponse(res, 'Could not login as user:' + user.email + ' password:' + user.password);
|
||||
common.verifyResponse(res, 'Could not login as user:' + user.email + ' password:' + user.password);
|
||||
return res.body.accessToken;
|
||||
};
|
||||
|
||||
@ -46,7 +38,7 @@ AppStore.prototype.waitForCloudron = function (boxId) {
|
||||
sleep(10);
|
||||
process.stdout.write('.');
|
||||
res = request.get(this._origin + '/api/v1/cloudrons/' + boxId).query({ accessToken: this._credentials.accessToken }).end();
|
||||
verifyResponse(res, 'Could not query cloudron status');
|
||||
common.verifyResponse(res, 'Could not query cloudron status');
|
||||
|
||||
boxInfo = res.body.box;
|
||||
if (boxInfo.status === 'ready') {
|
||||
@ -72,7 +64,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();
|
||||
verifyResponse(res, 'Could not create cloudron');
|
||||
common.verifyResponse(res, 'Could not create cloudron');
|
||||
|
||||
debug('Cloudron %s created'.green, box.domain);
|
||||
return res.body.box;
|
||||
@ -84,18 +76,18 @@ AppStore.prototype.deleteCloudron = function (box) {
|
||||
.set('X-HTTP-Method-Override', 'DELETE')
|
||||
.send({ password: this._credentials.password })
|
||||
.end();
|
||||
verifyResponse(res, 'Could not delete cloudron');
|
||||
common. verifyResponse(res, 'Could not delete cloudron');
|
||||
};
|
||||
|
||||
AppStore.prototype.getManifest = function (appId, version) {
|
||||
var res = request.get(this._origin + '/api/v1/apps/' + appId + '/versions/' + version).end();
|
||||
verifyResponse(res, 'Could not get get app manifest');
|
||||
common.verifyResponse(res, 'Could not get get app manifest');
|
||||
return res.body.manifest;
|
||||
};
|
||||
|
||||
AppStore.prototype.restore = function (boxId, backupId) {
|
||||
var res = request.post(this._origin + '/api/v1/cloudrons/' + boxId + '/restore/' + backupId).query({ accessToken: this._credentials.accessToken }).end();
|
||||
verifyResponse(res, 'Could not restore cloudron');
|
||||
common.verifyResponse(res, 'Could not restore cloudron');
|
||||
};
|
||||
|
||||
AppStore.prototype.setupBilling = function (callback) {
|
||||
@ -121,7 +113,7 @@ AppStore.prototype.setupBilling = function (callback) {
|
||||
};
|
||||
|
||||
var res = request.put(that._origin + '/api/v1/users').send(data).query({ accessToken: that._credentials.accessToken }).end();
|
||||
verifyResponse(res, 'Could not setup billing');
|
||||
common.verifyResponse(res, 'Could not setup billing');
|
||||
|
||||
callback(null);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user