consterr=newError(`You are attempting to use a custom domain alias (${chalk.underline(chalk.cyan(alias))}), but this is only enabled for premium accounts. Please upgrade at ${chalk.underline('https://zeit.co/account')}`);
err.userError=true;
returnbail(err);
}
if('alias_in_use'===code){
consterr=newError(`The alias you are trying to configure (${chalk.underline(chalk.cyan(alias))}) is already in use by a different account.`);
err.userError=true;
returnbail(err);
}
returnbail(newError('Authorization error'));
}
// all other errors
if(body.error){
constcode=body.error.code;
if('deployment_not_found'===code){
returnbail(newError('Deployment not found'));
}
if('cert_missing'===code){
console.log(`> Provisioning certificate for ${chalk.underline(chalk.cyan(alias))}`);
awaitthis.verifyOwnership();
awaitthis.createCert();
// try again, but now having provisioned the certificate
returnthis.createAlias(depl,alias);
}
returnbail(newError(body.error.message));
}
// the two expected succesful cods are 200 and 304
if(200!==res.status&&304!==res.status){
thrownewError('Unhandled error');
}
});
}
asyncverifyOwnership(domain){
returnthis.retry(async(bail,attempt)=>{
consttargets=awaitresolve4('alias.zeit.co');
if(!targets.length){
returnbail(newError('Unable to resolve alias.zeit.co'));
}
constips=awaitresolve4(domain);
if(!ips.length){
consterr=newError('The domain ${domain} A record in the DNS configuration is not returning any IPs.');
err.userError=true;
returnbail(err);
}
for(constipofips){
if(!~targets.indexOf(ip)){
consterr=newError(`The domain ${domain} has an A record ${chalk.bold(ip)} that doesn\'t resolve to ${chalk.bold('alias.zeit.co')}. Make sure the appropriate \`ALIAS\` or \`CNAME\` records are configured.`);
consterr=newError(`We couldn't verify ownership of the domain ${domain}. Make sure the appropriate \`ALIAS\` or \`CNAME\` records are configured and pointing to ${chalk.bold('alias.zeit.co')}.`);