diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-05-28 19:01:51 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-07-07 15:36:25 +0200 |
commit | 5950b87dacf07eebbc58beb9a21781a8abc958e4 (patch) | |
tree | 433105d1793c809584a6cc87763b124153644d2c /modules | |
parent | 6edc057451ebade744aa62cca64aa685eb6021ce (diff) |
luci-base: luci.js: make require() failures catcheable
Refactor L.require() to use L.raise() instead of L.error() to signal
class loading failures. This allows callers to handle class loading
errors in a graceful manner.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/luci.js | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 6332790c77..853bbfc05d 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -658,7 +658,7 @@ if (classes[name] != null) { /* Circular dependency */ if (from.indexOf(name) != -1) - L.error('DependencyError', + L.raise('DependencyError', 'Circular dependency: class "%s" depends on "%s"', name, from.join('" which depends on "')); @@ -670,7 +670,7 @@ var compileClass = function(res) { if (!res.ok) - L.error('NetworkError', + L.raise('NetworkError', 'HTTP error %d while loading class file "%s"', res.status, url); var source = res.text(), @@ -721,7 +721,7 @@ .format(args, source, res.url)); } catch (error) { - L.error('SyntaxError', '%s\n in %s:%s', + L.raise('SyntaxError', '%s\n in %s:%s', error.message, res.url, error.lineNumber || '?'); } @@ -751,9 +751,7 @@ }; /* Request class file */ - classes[name] = Request.get(url, { cache: true }) - .then(compileClass) - .catch(L.error); + classes[name] = Request.get(url, { cache: true }).then(compileClass); return classes[name]; }, |