Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix(core): prevent TypeError when handling unhandledRejection (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
yassere authored Jun 28, 2021
1 parent 34a7b26 commit aeec422
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/core/common/FatalErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ export default class FatalErrorHandler {
}

public setupGlobalHandlers(): Resource {
process.on("uncaughtException", this.handleBound);
process.on("unhandledRejection", this.handleBound);
// Only pass first argument to handler
const handleError = (err: Error) => this.handleBound(err);

process.on("uncaughtException", handleError);
process.on("unhandledRejection", handleError);

return createResourceFromCallback(
"FatalErrorHandlerEvents",
() => {
process.removeListener("uncaughtException", this.handleBound);
process.removeListener("unhandledRejection", this.handleBound);
process.removeListener("uncaughtException", handleError);
process.removeListener("unhandledRejection", handleError);
},
);
}
Expand Down

0 comments on commit aeec422

Please sign in to comment.