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:
parent
bce961729d
commit
763158600a
1 changed files with 5 additions and 4 deletions
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue