luci-base: luci.js: fix `LuCI.request.poll.add()` exception handling 4742/head
authorGiovanni Giacobbi <giovanni@giacobbi.net>
Mon, 18 Jan 2021 09:50:43 +0000 (10:50 +0100)
committerGiovanni Giacobbi <giovanni@giacobbi.net>
Tue, 19 Jan 2021 21:46:25 +0000 (22:46 +0100)
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>
modules/luci-base/htdocs/luci-static/resources/luci.js

index faed3aa6d2c7e76a6b0c47aa5a3eb86a48d23d9b..eeb48530c8e980aee32a2ac8205765a034b58dc3 100644 (file)
                                                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);
                                        });
                                };