diff --git a/bin/now-certs.js b/bin/now-certs.js index 4a7e69c..8571ab7 100755 --- a/bin/now-certs.js +++ b/bin/now-certs.js @@ -108,7 +108,7 @@ if (argv.help || !subcommand) { function formatExpirationDate(date) { const diff = date - Date.now() - return diff < 0 ? chalk.gray(ms(new Date(-diff)) + ' ago') : chalk.gray('in ' + ms(new Date(diff))) + return diff < 0 ? chalk.gray(ms(-diff) + ' ago') : chalk.gray('in ' + ms(diff)) } async function run(token) { @@ -172,6 +172,10 @@ async function run(token) { } else { // Issue a standard certificate cert = await certs.create(cn) } + if (!cert) { + // Cert is undefined and "Cert is alread issued" has been printed to stdout + return exit(1) + } const elapsed = ms(new Date() - start) console.log(`${chalk.cyan('> Success!')} Certificate entry ${chalk.bold(cn)} ${chalk.gray(`(${cert.uid})`)} created ${chalk.gray(`[${elapsed}]`)}`) } else if (subcommand === 'renew') { diff --git a/lib/alias.js b/lib/alias.js index fd3236f..66f72fb 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -196,7 +196,11 @@ export default class Alias extends Now { this._agent.close() this._agent._initAgent() - const {created, uid} = await this.createAlias(depl, alias) + const newAlias = await this.createAlias(depl, alias) + if (!newAlias || !newAlias.created) { + throw new Error(`Unexpected error occurred while setting up alias: ${JSON.stringify(newAlias)}`) + } + const {created, uid} = newAlias if (created) { console.log(`${chalk.cyan('> Success!')} Alias created ${chalk.dim(`(${uid})`)}: ${chalk.bold(chalk.underline(`https://${alias}`))} now points to ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)}`) } else {