diff --git a/src/static/js/pad_utils.js b/src/static/js/pad_utils.js index 83ee9aae8..c6aeef77f 100644 --- a/src/static/js/pad_utils.js +++ b/src/static/js/pad_utils.js @@ -500,30 +500,34 @@ var padutils = { } }; -var globalExceptionHandler = undefined; -function setupGlobalExceptionHandler() { - if (!globalExceptionHandler) { - globalExceptionHandler = function test (msg, url, linenumber) - { - var errorId = randomString(20); - if ($("#editorloadingbox").attr("display") != "none"){ - //show javascript errors to the user - $("#editorloadingbox").css("padding", "10px"); - $("#editorloadingbox").css("padding-top", "45px"); - $("#editorloadingbox").html("
An error occured
The error was reported with the following id: '" + errorId + "'

Please send this error message to us:
'" - + "ErrorId: " + errorId + "
UserAgent: " + navigator.userAgent + "
" + msg + " in " + url + " at line " + linenumber + "'
"); - } +function globalExceptionHandler(msg, url, linenumber) { + var errorId = randomString(20); + if ($("#editorloadingbox").attr("display") != "none"){ + //show javascript errors to the user + $("#editorloadingbox").css("padding", "10px"); + $("#editorloadingbox").css("padding-top", "45px"); + $("#editorloadingbox").html("
An error occured
The error was reported with the following id: '" + errorId + "'

Please send this error message to us:
'" + + "ErrorId: " + errorId + "
UserAgent: " + navigator.userAgent + "
" + msg + " in " + url + " at line " + linenumber + "'
"); + } - //send javascript errors to the server - var errObj = {errorInfo: JSON.stringify({errorId: errorId, msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})}; - var loc = document.location; - var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror"; - - $.post(url, errObj); - - return false; - }; + //send javascript errors to the server + var errObj = {errorInfo: JSON.stringify({errorId: errorId, msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})}; + var loc = document.location; + var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror"; + + $.post(url, errObj); + + return false; +} + +var globalExceptionHandlerSetup = false; +function setupGlobalExceptionHandler() { + if (!globalExceptionHandlerSetup) { + globalExceptionHandlerSetup = true; window.onerror = globalExceptionHandler; + } else { + // no-op + // TODO: Throw an exception here. } }