From d8faeff64de136976bfa5593cac51eb85d13386b Mon Sep 17 00:00:00 2001 From: Renzo Tomlinson Date: Mon, 13 Apr 2020 18:48:22 -0600 Subject: [PATCH] make calls to remove resolve before returning --- acme.js | 68 +++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/acme.js b/acme.js index 3d829a7..6207cec 100644 --- a/acme.js +++ b/acme.js @@ -774,50 +774,32 @@ ACME._postChallenge = function(me, options, kid, auth) { // REMOVE DNS records as soon as the state is non-processing // (valid or invalid or other) - try { - options.challenges[auth.type] - .remove({ challenge: auth }) - .catch(function(err) { - err.action = 'challenge_remove'; - err.altname = auth.altname; - err.type = auth.type; - ACME._notify(me, options, 'error', err); - }); - } catch (e) {} - - if ('valid' === resp.body.status) { - if (me.debug) { - console.debug('poll: valid'); - } - - return resp.body; - } - var errmsg; - if (!resp.body.status) { - errmsg = - "[ACME.js] (E_STATE_EMPTY) empty challenge state for '" + - altname + - "':" + - JSON.stringify(resp.body); - } else if ('invalid' === resp.body.status) { - errmsg = - "[ACME.js] (E_STATE_INVALID) challenge state for '" + - altname + - "': '" + - //resp.body.status + - JSON.stringify(resp.body) + - "'"; - } else { - errmsg = - "[ACME.js] (E_STATE_UKN) challenge state for '" + - altname + - "': '" + - resp.body.status + - "'"; - } - - return Promise.reject(new Error(errmsg)); + return options.challenges[auth.type] + .remove({ challenge: auth }) + .then((res) => { + if ("valid" === resp.body.status) { + if (me.debug) { + console.debug("poll: valid"); + } + return resp.body; + } + return Promise.reject("status not valid"); + }) + .catch(function (err) { + if (!resp.body.status) { + errmsg = "[ACME.js] (E_STATE_EMPTY) empty challenge state for '" + altname + "':" + JSON.stringify(resp.body); + } else if ("invalid" === resp.body.status) { + errmsg = "[ACME.js] (E_STATE_INVALID) challenge state for '" + altname + "': '" + JSON.stringify(resp.body) + "'"; + } else { + errmsg = "[ACME.js] (E_STATE_UKN) challenge state for '" + altname + "': '" + resp.body.status + "'"; + } + err.action = "challenge_remove"; + err.altname = auth.altname; + err.type = auth.type; + ACME._notify(me, options, "error", err); + return Promise.reject(new Error(errmsg)); + }); } function transformError(e) { -- 2.38.5