From 71fc6d45bd761a9d2715faa68f2b8c0271ee7169 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 13:38:13 +0300 Subject: refactor error reporting to AppBase; keep exception_error() for now as a shim --- js/common.js | 75 ++++++++---------------------------------------------------- 1 file changed, 10 insertions(+), 65 deletions(-) (limited to 'js/common.js') diff --git a/js/common.js b/js/common.js index de6d13a78..427e3034c 100755 --- a/js/common.js +++ b/js/common.js @@ -4,6 +4,16 @@ let _label_base_index = -1024; let loading_progress = 0; +/* error reporting shim */ + +// TODO: deprecated; remove +function exception_error(e, e_compat, filename, lineno, colno) { + if (typeof e == "string") + e = e_compat; + + App.Error.report(e, {filename: filename, lineno: lineno, colno: colno}); +} + /* xhr shorthand helpers */ function xhrPost(url, params, complete) { @@ -118,71 +128,6 @@ const Cookie = { } }; -/* error reporting */ - -function report_error(message, filename, lineno, colno, error) { - exception_error(error, null, filename, lineno); -} - -function exception_error(e, e_compat, filename, lineno, colno) { - if (typeof e == "string") e = e_compat; - - if (!e) return; // no exception object, nothing to report. - - try { - console.error(e); - const msg = e.toString(); - - try { - xhrPost("backend.php", - {op: "rpc", method: "log", - file: e.fileName ? e.fileName : filename, - line: e.lineNumber ? e.lineNumber : lineno, - msg: msg, context: e.stack}, - (transport) => { - console.warn(transport.responseText); - }); - - } catch (e) { - console.error("Exception while trying to log the error.", e); - } - - let content = "

" + msg + "

"; - - if (e.stack) { - content += "
Stack trace:
" + - ""; - } - - content += "
"; - - content += "
"; - - content += ""; - content += "
"; - - if (dijit.byId("exceptionDlg")) - dijit.byId("exceptionDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "exceptionDlg", - title: "Unhandled exception", - style: "width: 600px", - content: content}); - - dialog.show(); - - } catch (ei) { - console.error("Exception while trying to report an exception:", ei); - console.error("Original exception:", e); - - alert("Exception occured while trying to report an exception.\n" + - ei.stack + "\n\nOriginal exception:\n" + e.stack); - } -} - /* runtime notifications */ const Notify = { -- cgit v1.2.3