luci-base: luci.js: tweak error handling
If the ui class is loaded, use its modalDialog facility to display runtime errors, alternatively render them into the maincontent area. Also prevent duplication of stack trace information and throw a low level error on session expiration to allow higher layers to properly handle it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
fda4ba598c
commit
5b7924c808
1 changed files with 12 additions and 2 deletions
|
@ -488,12 +488,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append shortened & beautified stacktrace to message */
|
/* Append shortened & beautified stacktrace to message */
|
||||||
e.message += '\n' + stack.join('\n')
|
var trace = stack.join('\n')
|
||||||
.replace(/(.*?)@(.+):(\d+):(\d+)/g, ' at $1 ($2:$3:$4)');
|
.replace(/(.*?)@(.+):(\d+):(\d+)/g, ' at $1 ($2:$3:$4)');
|
||||||
|
|
||||||
|
if (e.message.indexOf(trace) == -1)
|
||||||
|
e.message += '\n' + trace;
|
||||||
|
|
||||||
if (window.console && console.debug)
|
if (window.console && console.debug)
|
||||||
console.debug(e);
|
console.debug(e);
|
||||||
|
|
||||||
|
if (this.ui)
|
||||||
|
this.ui.showModal(_('Runtime error'),
|
||||||
|
E('pre', { 'class': 'alert-message error' }, e));
|
||||||
|
else
|
||||||
|
L.dom.content(document.querySelector('#maincontent'),
|
||||||
|
E('pre', { 'class': 'alert-message error' }, e));
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -610,7 +620,7 @@
|
||||||
}, _('To login…')))
|
}, _('To login…')))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
L.error('AuthenticationError', 'Session expired');
|
throw 'Session expired';
|
||||||
});
|
});
|
||||||
|
|
||||||
originalCBIInit();
|
originalCBIInit();
|
||||||
|
|
Loading…
Reference in a new issue