excessively log pairing states

This commit is contained in:
AJ ONeal 2018-07-08 02:50:03 +00:00
parent cc2823a56a
commit 5aed381963
1 changed files with 9 additions and 2 deletions

View File

@ -405,30 +405,37 @@ app.get(urls.pairState, function (req, res) {
// or respond after time if it does not complete
var auth = Auths.get(req.params.id); // id or secret accepted
if (!auth) {
console.log("[pair_state] invalid (bad state id)", req.params.id);
res.send({ status: 'invalid' });
return;
}
function check(i) {
console.log("[pair_state] check i =", i, req.params.id);
if (auth._claimed) {
console.log("[pair_state] complete", req.params.id);
res.send({
status: 'complete'
});
} else if (auth._offered) {
console.log("[pair_state] ready", req.params.id);
res.send({
status: 'ready', access_token: auth.authz
, grant: { domains: auth.domains || [], ports: auth.ports || [] }
});
} else if (false === auth._offered) {
console.log("[pair_state] failed", req.params.id);
res.send({ status: 'failed', error: { message: "device pairing failed" } });
} else if (i >= 5) {
} else if (i >= 7) {
console.log("[pair_state] overdue i =", i, req.params.id);
var stateUrl = 'https://' + req._state.config.apiDomain + urls.pairState.replace(/:id/g, auth.id);
res.statusCode = 200;
res.setHeader('Location', stateUrl);
res.setHeader('Link', '<' + stateUrl + '>;rel="next"');
res.send({ status: 'pending' });
} else {
setTimeout(check, 3 * 1000, i + 1);
console.log("[pair_state] try again i =", i, req.params.id);
setTimeout(check, 250, i + 1);
}
}
check(0);