This commit is contained in:
Chad Weider 2013-02-18 12:18:11 -08:00
commit f6eeb3ba1b

View file

@ -509,30 +509,35 @@ var padutils = {
} }
}; };
var globalExceptionHandler = undefined; function globalExceptionHandler(msg, url, linenumber) {
function setupGlobalExceptionHandler() { var errorId = randomString(20);
if (!globalExceptionHandler) { if ($("#editorloadingbox").attr("display") != "none"){
globalExceptionHandler = function test (msg, url, linenumber) //show javascript errors to the user
{ $("#editorloadingbox").css("padding", "10px");
var errorId = randomString(20); $("#editorloadingbox").css("padding-top", "45px");
if ($("#editorloadingbox").attr("display") != "none"){ // TODO: Use Mustache
//show javascript errors to the user $("#editorloadingbox").html("<div style='text-align:left;color:red;font-size:16px;'><b>An error occured</b><br>The error was reported with the following id: '" + Security.escapeHTML(errorId) + "'<br><br><span style='color:black;font-weight:bold;font-size:16px'>Please send this error message to us: </span><div style='color:black;font-size:14px'>'"
$("#editorloadingbox").css("padding", "10px"); + "ErrorId: " + Security.escapeHTML(errorId) + "<br>UserAgent: " + Security.escapeHTML(navigator.userAgent) + "<br>" + Security.escapeHTML(msg) + " in " + Security.escapeHTML(url) + " at line " + Security.escapeHTML(linenumber) + "'</div></div>");
$("#editorloadingbox").css("padding-top", "45px"); }
$("#editorloadingbox").html("<div style='text-align:left;color:red;font-size:16px;'><b>An error occured</b><br>The error was reported with the following id: '" + errorId + "'<br><br><span style='color:black;font-weight:bold;font-size:16px'>Please send this error message to us: </span><div style='color:black;font-size:14px'>'"
+ "ErrorId: " + errorId + "<br>UserAgent: " + navigator.userAgent + "<br>" + msg + " in " + url + " at line " + linenumber + "'</div></div>");
}
//send javascript errors to the server //send javascript errors to the server
var errObj = {errorInfo: JSON.stringify({errorId: errorId, msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})}; var errObj = {errorInfo: JSON.stringify({errorId: errorId, msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})};
var loc = document.location; var loc = document.location;
var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror"; var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror";
$.post(url, errObj); $.post(url, errObj);
return false; return false;
}; }
var globalExceptionHandlerSetup = false;
function setupGlobalExceptionHandler() {
if (!globalExceptionHandlerSetup) {
globalExceptionHandlerSetup = true;
window.onerror = globalExceptionHandler; window.onerror = globalExceptionHandler;
} else {
// no-op
// TODO: Throw an exception here.
} }
} }