Skip to content

Instantly share code, notes, and snippets.

@Chudesnov
Last active January 29, 2018 13:49
Show Gist options
  • Save Chudesnov/8335952b4997176010c51922e6fd1547 to your computer and use it in GitHub Desktop.
Save Chudesnov/8335952b4997176010c51922e6fd1547 to your computer and use it in GitHub Desktop.
// Listen to all errors
this.errorEventListener = event => {
if (this._isSet) {
global.removeEventListener('error', this.uncaughtErrorHandler); // remove from the queue in case it was previously added
}
global.addEventListener('error', this.uncaughtErrorHandler); // should always get appended the end of the list.
this._isSet = true; // set a flag to check in later error events.
}
// Report uncaught errors.
this.uncaughtErrorHandler = event => {
if (!event.defaultPrevented) {
process.emit('uncaughtException', event.error);
event.preventDefault(); // we still need to prevent because jsdom will print the error to console.error otherwise
}
};
global.addEventListener('error', this.errorEventListener); // this must be the first handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment