Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Created July 25, 2014 20:01
Show Gist options
  • Save fedesilva/93b0f35f988087aed911 to your computer and use it in GitHub Desktop.
Save fedesilva/93b0f35f988087aed911 to your computer and use it in GitHub Desktop.
JS Global Exception Handler
window.onerror = function (exception, source, line) {
try {
var url = "/logs/error";
var error = _.isObject(exception) ? JSON.stringify(exception) : exception.toString();
var data = "Global error ["+error+"] in "+source+":"+line;
console.error('error caught! ');
console.error(exception);
$.ajax({
type: "POST",
url: url,
data: data,
success: function(d){console.log(d)},
dataType: "text"
});
} catch (e) {
console.error(e)
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment