luci-base: luci.js: fix LuCI.request.poll.add() exception handling

The try/catch is meant for the `res.json()` call and should apply to that. As it was before, an exception inside the poll callback would cause the callback to be reinvoked without the JSON parameter, which is an odd behaviour. Moreover, it makes it hard to debug because it is completely hidden from the browser console. We now differentiate between exceptions thrown due to bad JSON in `responseText` from exceptions generated inside the callback itself, which are let through for browser console logging.

Signed-off-by: Giovanni Giacobbi <giovanni@giacobbi.net>
This commit is contained in:
Giovanni Giacobbi 2021-01-18 10:50:43 +01:00
parent bce961729d
commit 763158600a
No known key found for this signature in database
GPG key ID: 63A98B68F17EE59B

View file

@ -982,12 +982,13 @@
if (!Poll.active())
return;
var res_json = null;
try {
callback(res, res.json(), res.duration);
}
catch (err) {
callback(res, null, res.duration);
res_json = res.json();
}
catch (err) {}
callback(res, res_json, res.duration);
});
};