From 119f5a9ae4f28c9a1214a860a68cedb38398ad11 Mon Sep 17 00:00:00 2001 From: John Shaver Date: Tue, 5 Jun 2018 16:07:54 -0700 Subject: [PATCH] Fixed error handling for non promise setChallenge. --- node.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/node.js b/node.js index fa26105..50927e5 100644 --- a/node.js +++ b/node.js @@ -384,15 +384,10 @@ ACME._postChallenge = function (me, options, identifier, ch) { me._nonce = resp.toJSON().headers['replay-nonce']; if (me.debug) console.debug('respond to challenge: resp.body:'); if (me.debug) console.debug(resp.body); - return ACME._wait(1 * 1000).then(pollStatus).then(resolve, reject); + return ACME._wait(1 * 1000).then(pollStatus); }); } - function failChallenge(err) { - if (err) { reject(err); return; } - return testChallenge(); - } - function testChallenge() { // TODO put check dns / http checks here? // http-01: GET https://example.org/.well-known/acme-challenge/{{token}} => {{keyAuth}} @@ -410,11 +405,23 @@ ACME._postChallenge = function (me, options, identifier, ch) { try { if (1 === options.setChallenge.length) { - options.setChallenge(auth).then(testChallenge, reject); + options.setChallenge(auth).then(testChallenge).then(resolve, reject); } else if (2 === options.setChallenge.length) { - options.setChallenge(auth, failChallenge); + options.setChallenge(auth, function(err) { + if(err) { + reject(err); + } else { + testChallenge().then(resolve, reject); + } + }); } else { - options.setChallenge(identifier.value, ch.token, keyAuthorization, failChallenge); + options.setChallenge(identifier.value, ch.token, keyAuthorization, function(err) { + if(err) { + reject(err); + } else { + testChallenge().then(resolve, reject); + } + }); } } catch(e) { reject(e);