Last active
May 13, 2016 19:27
-
-
Save kirankumaramruthaluri/bb6180913a86db298de0aa9435aa64d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Global error event handler in javascript in browser in both async and sync operations | |
* window - signifies the browser context | |
* 'error' - event name | |
* @param e Evemt object of the error occurred to print the stack | |
* / | |
window.addEventListener('error', function (e) { | |
var stack = e.error.stack; | |
var message = e.error.toString(); | |
if (stack) { | |
message += '\n' + stack; | |
} | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', '/log', true); | |
xhr.send(message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment