Skip to content

Instantly share code, notes, and snippets.

@kirantemojo
Last active May 13, 2016 19:27
Show Gist options
  • Save kirantemojo/bb6180913a86db298de0aa9435aa64d1 to your computer and use it in GitHub Desktop.
Save kirantemojo/bb6180913a86db298de0aa9435aa64d1 to your computer and use it in GitHub Desktop.
/**
* 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