luci-base: luci.js: tweak error handling
authorJo-Philipp Wich <jo@mein.io>
Mon, 1 Apr 2019 13:30:42 +0000 (15:30 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 13:25:49 +0000 (15:25 +0200)
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>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 07e8d8c88731c4ea7086c9be7d9d9ba7be1ba21c..c71865f96fc18063c207080e78c8e0f91a2e4f0a 100644 (file)
                        }
 
                        /* 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)');
 
+                       if (e.message.indexOf(trace) == -1)
+                               e.message += '\n' + trace;
+
                        if (window.console && console.debug)
                                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;
                },
 
                                                }, _('To login…')))
                                ]);
 
-                               L.error('AuthenticationError', 'Session expired');
+                               throw 'Session expired';
                        });
 
                        originalCBIInit();