Created
November 14, 2019 06:05
-
-
Save numToStr/f8f222b9264685129176fceeaebcc042 to your computer and use it in GitHub Desktop.
Node.js interruptions
This file contains hidden or 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 errorHandler = (error, event) => { | |
if (error) { | |
throw error; | |
} | |
throw new Error(`${event} caught`); | |
}; | |
process.on("beforeExit", () => errorHandler(null, "beforeExit")); | |
process.on("exit", () => errorHandler(null, "exit")); | |
process.on("unhandledRejection", error => { | |
errorHandler(error, "unhandledRejection"); | |
}); | |
process.on("uncaughtException", error => | |
errorHandler(error, "uncaughtException") | |
); | |
process.on("SIGINT", () => errorHandler(null, "SIGINT")); | |
process.on("SIGQUIT", () => errorHandler(null, "SIGQUIT")); | |
process.on("SIGTERM", () => errorHandler(null, "SIGTERM")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment