Skip to content

Commit

Permalink
refactor(dev): use trapUnhandledNodeErrors utility
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 16, 2023
1 parent 61bc43e commit 4111798
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/runtime/entries/nitro-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { mkdirSync } from "node:fs";
import { threadId, parentPort } from "node:worker_threads";
import { isWindows, provider } from "std-env";
import { toNodeListener } from "h3";
import gracefulShutdown from "http-graceful-shutdown";
import { nitroApp } from "../app";
import { trapUnhandledNodeErrors } from "../utils";

const server = new Server(toNodeListener(nitroApp.h3App));

Expand Down Expand Up @@ -37,21 +37,8 @@ const listener = server.listen(listenAddress, () => {
});
});

if (process.env.DEBUG) {
process.on("unhandledRejection", (err) =>
console.error("[nitro] [dev] [unhandledRejection]", err)
);
process.on("uncaughtException", (err) =>
console.error("[nitro] [dev] [uncaughtException]", err)
);
} else {
process.on("unhandledRejection", (err) =>
console.error("[nitro] [dev] [unhandledRejection] " + err)
);
process.on("uncaughtException", (err) =>
console.error("[nitro] [dev] [uncaughtException] " + err)
);
}
// Trap unhandled errors
trapUnhandledNodeErrors();

// Graceful shutdown
async function onShutdown(signal?: NodeJS.Signals) {
Expand Down

0 comments on commit 4111798

Please sign in to comment.