Last active
January 29, 2018 13:49
-
-
Save Chudesnov/8335952b4997176010c51922e6fd1547 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
// 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