Skip to content

Instantly share code, notes, and snippets.

@numToStr
Created November 14, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numToStr/f8f222b9264685129176fceeaebcc042 to your computer and use it in GitHub Desktop.
Save numToStr/f8f222b9264685129176fceeaebcc042 to your computer and use it in GitHub Desktop.
Node.js interruptions
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