Browse Source

Improve error handling when issuing cert fails (#154)

Fix `now certs ls` error when showing expiration date
Improve logging for when alias creation fails
master
Jarmo Isotalo 8 years ago
committed by Olli Vanhoja
parent
commit
4de1c69b6a
  1. 6
      bin/now-certs.js
  2. 6
      lib/alias.js

6
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') {

6
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 {

Loading…
Cancel
Save