Browse Source

alias: handle 409

master
Guillermo Rauch 9 years ago
parent
commit
7bcea8e19d
  1. 15
      lib/alias.js

15
lib/alias.js

@ -144,8 +144,12 @@ export default class Alias extends Now {
await this.verifyOwnership(alias); await this.verifyOwnership(alias);
} }
await this.createAlias(depl, alias); const { created, uid } = await this.createAlias(depl, alias);
console.log(`${chalk.cyan('> Success!')} Deployment ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)} now points to ${chalk.bold(chalk.underline(`https://${alias}`))}`); if (created) {
console.log(`${chalk.cyan('> Success!')} Alias created ${chalk.dim(`(${uid})`)}: ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)} now points to ${chalk.bold(chalk.underline(`https://${alias}`))}`);
} else {
console.log(`${chalk.cyan('> Success!')} Alias already exists ${chalk.dim(`(${uid})`)}.`);
}
} }
createAlias (depl, alias) { createAlias (depl, alias) {
@ -156,11 +160,12 @@ export default class Alias extends Now {
body: { alias } body: { alias }
}); });
if (304 === res.status) return;
const body = await res.json(); const body = await res.json();
if (this._debug) console.timeEnd(`> [debug] /now/deployments/${depl.uid}/aliases #${attempt}`); if (this._debug) console.timeEnd(`> [debug] /now/deployments/${depl.uid}/aliases #${attempt}`);
// 409 conflict is returned if it already exists
if (409 === res.status) return { uid: body.error.uid };
// no retry on authorization problems // no retry on authorization problems
if (403 === res.status) { if (403 === res.status) {
const code = body.error.code; const code = body.error.code;
@ -204,6 +209,8 @@ export default class Alias extends Now {
if (200 !== res.status && 304 !== res.status) { if (200 !== res.status && 304 !== res.status) {
throw new Error('Unhandled error'); throw new Error('Unhandled error');
} }
return body;
}); });
} }

Loading…
Cancel
Save