Created
April 5, 2020 13:36
-
-
Save omrilotan/073fe56c81ce488d96b17e5b85373a20 to your computer and use it in GitHub Desktop.
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
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