make calls to remove resolve before returning

This commit is contained in:
Renzo Tomlinson 2020-04-13 18:48:22 -06:00
parent aa324e2a29
commit d8faeff64d
1 changed files with 25 additions and 43 deletions

68
acme.js
View File

@ -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) {