Created
July 25, 2014 20:01
-
-
Save fedesilva/93b0f35f988087aed911 to your computer and use it in GitHub Desktop.
JS Global Exception Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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