From 763158600a348b0d4b16b0b8bef052b213d92d2b Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Mon, 18 Jan 2021 10:50:43 +0100 Subject: 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 --- modules/luci-base/htdocs/luci-static/resources/luci.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules/luci-base') diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index faed3aa6d2..eeb48530c8 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -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); }); }; -- cgit v1.2.3