mirror of https://git.openwrt.org/project/luci.git
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>
This commit is contained in:
parent
6edc057451
commit
5950b87dac
|
@ -658,7 +658,7 @@
|
||||||
if (classes[name] != null) {
|
if (classes[name] != null) {
|
||||||
/* Circular dependency */
|
/* Circular dependency */
|
||||||
if (from.indexOf(name) != -1)
|
if (from.indexOf(name) != -1)
|
||||||
L.error('DependencyError',
|
L.raise('DependencyError',
|
||||||
'Circular dependency: class "%s" depends on "%s"',
|
'Circular dependency: class "%s" depends on "%s"',
|
||||||
name, from.join('" which depends on "'));
|
name, from.join('" which depends on "'));
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@
|
||||||
|
|
||||||
var compileClass = function(res) {
|
var compileClass = function(res) {
|
||||||
if (!res.ok)
|
if (!res.ok)
|
||||||
L.error('NetworkError',
|
L.raise('NetworkError',
|
||||||
'HTTP error %d while loading class file "%s"', res.status, url);
|
'HTTP error %d while loading class file "%s"', res.status, url);
|
||||||
|
|
||||||
var source = res.text(),
|
var source = res.text(),
|
||||||
|
@ -721,7 +721,7 @@
|
||||||
.format(args, source, res.url));
|
.format(args, source, res.url));
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
L.error('SyntaxError', '%s\n in %s:%s',
|
L.raise('SyntaxError', '%s\n in %s:%s',
|
||||||
error.message, res.url, error.lineNumber || '?');
|
error.message, res.url, error.lineNumber || '?');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,9 +751,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Request class file */
|
/* Request class file */
|
||||||
classes[name] = Request.get(url, { cache: true })
|
classes[name] = Request.get(url, { cache: true }).then(compileClass);
|
||||||
.then(compileClass)
|
|
||||||
.catch(L.error);
|
|
||||||
|
|
||||||
return classes[name];
|
return classes[name];
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue