From 6c054cf24168c70efb68db16f838e96082ed1ca8 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 11 May 2018 15:07:28 -0600 Subject: [PATCH] Add logging for approveDomains errors. Addresses https://git.coolaj86.com/coolaj86/greenlock-express.js/issues/8 --- index.js | 57 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index c99a8ed..153b1c8 100644 --- a/index.js +++ b/index.js @@ -273,36 +273,53 @@ LE.create = function (le) { log(le.debug, 'le.getCertificates called for', domain, 'with certs for', certs && certs.altnames || 'NONE'); var opts = { domain: domain, domains: certs && certs.altnames || [ domain ] }; - le.approveDomains(opts, certs, function (_err, results) { - if (_err) { - log(le.debug, 'le.approveDomains called with error', _err); - cb(_err); - return; - } + try { + le.approveDomains(opts, certs, function (_err, results) { + if (_err) { + log(le.debug, 'le.approveDomains called with error', _err); + cb(_err); + return; + } - log(le.debug, 'le.approveDomains called with certs for', results.certs && results.certs.altnames || 'NONE', 'and options:'); - log(le.debug, results.options); + log(le.debug, 'le.approveDomains called with certs for', results.certs && results.certs.altnames || 'NONE', 'and options:'); + log(le.debug, results.options); - var promise; + var promise; - if (results.certs) { - log(le.debug, 'le renewing'); - promise = le.core.certificates.renewAsync(results.options, results.certs); - } - else { - log(le.debug, 'le getting from disk or registering new'); - promise = le.core.certificates.getAsync(results.options); - } + if (results.certs) { + log(le.debug, 'le renewing'); + promise = le.core.certificates.renewAsync(results.options, results.certs); + } + else { + log(le.debug, 'le getting from disk or registering new'); + promise = le.core.certificates.getAsync(results.options); + } - return promise.then(function (certs) { cb(null, certs); }, cb); - }); + return promise.then(function (certs) { cb(null, certs); }, function (e) { + if (le.debug) { console.debug("Error"); console.debug(e); } + cb(e); + }); + }); + } catch(e) { + console.error("[ERROR] Something went wrong in approveDomains:"); + console.error(e); + console.error("BUT WAIT! Good news: It's probably your fault, so you can probably fix it."); + } }; } le.sni = le.sni || require('le-sni-auto'); if (le.sni.create) { le.sni = le.sni.create(le); } - le.tlsOptions.SNICallback = le.sni.sniCallback; + le.tlsOptions.SNICallback = function (domain, cb) { + try { + le.sni.sniCallback(domain, cb); + } catch(e) { + console.error("[ERROR] Something went wrong in the SNICallback:"); + console.error(e); + cb(e); + } + }; } if (!le.tlsOptions.key || !le.tlsOptions.cert) { le.tlsOptions = require('localhost.daplie.me-certificates').merge(le.tlsOptions);