Skip to content

Commit f6cf096

Browse files
committed
Clean up how start handles getDroplet_ response
1 parent 9a66094 commit f6cf096

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

src/cloud/digitalocean/provisioner.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,20 @@ class Provisioner {
7171
}).then((keys: KeyPair) => {
7272
// Get SSH keys
7373
this.state_.ssh = keys;
74-
return this.getDroplet_(name).catch((e: Error) => {
75-
// Droplet does not exist so continue creating new server
76-
return Promise.resolve<void>();
77-
});
78-
}).then((resp: any) => {
79-
if (resp) {
80-
// Droplet exists so return error
74+
return this.getDroplet_(name).then((unused :any) => {
75+
// Droplet exists so raise error
8176
return Promise.reject({
8277
'errcode': 'VM_AE',
8378
'message': 'Droplet ' + name + ' already exists'
8479
});
85-
}
86-
return this.setupDigitalOcean_(name, region, image, size);
87-
// Setup Digital Ocean (SSH key + droplet)
80+
}, (e: Error) => {
81+
// Droplet does not exist so continue creating new server
82+
// Setup Digital Ocean (SSH key + droplet)
83+
return this.setupDigitalOcean_(name, region, image, size);
84+
});
8885
}).then(() => {
89-
return this.doRequest_('GET', 'droplets/' + this.state_.cloud.vm.id);
9086
// Get the droplet's configuration
87+
return this.doRequest_('GET', 'droplets/' + this.state_.cloud.vm.id);
9188
}).then((resp: any) => {
9289
this.sendStatus_('CLOUD_DONE_VM');
9390
this.state_.cloud.vm = resp.droplet;
@@ -147,16 +144,14 @@ class Provisioner {
147144
} else {
148145
return Promise.reject(new Error('error deleting droplet'));
149146
}
150-
}).then(() => {
151-
return Promise.resolve<void>();
152147
});
153148
}
154149

155150
/**
156151
* Finds a droplet with this name
157152
* @param {String} droplet name, as a string
158-
* @return {Promise.<Object>}, returns droplet if exists
159-
* or undefined if it does not exist
153+
* @return {Promise.<Object>}, resolves with {droplet: droplet_with_name}
154+
* or rejects if droplet doesn't exist
160155
*/
161156
private getDroplet_ = (name: string) : Promise<Object> => {
162157
return this.doRequest_('GET', 'droplets').then((resp: any) => {

0 commit comments

Comments
 (0)