Skip to content

Instantly share code, notes, and snippets.

@omrilotan
Created April 5, 2020 13:36
Show Gist options
  • Save omrilotan/073fe56c81ce488d96b17e5b85373a20 to your computer and use it in GitHub Desktop.
Save omrilotan/073fe56c81ce488d96b17e5b85373a20 to your computer and use it in GitHub Desktop.
const { onerror } = window; // Existing onerror handlers
// Trust others adhere to onerror handling rules
window.onerror = (...args) => {
let handled; // is someone else taking care this error?
try {
handled = onerror && onerror.apply(window, args);
} catch (error) {
// Catch others' onerror errors
myOnErrorHandler(error.message, '', 0, 0, error);
} finally {
handled || myOnErrorHandler(...args);
}
return false;
}
// Or simply be first and catch everything
window.onerror = (...args) => {
myOnErrorHandler(...args);
onerror && onerror.apply(window, args);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment