From 4111798a09fde7bf5916500637e27d6acc0189d1 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 16 May 2023 13:53:46 +0200 Subject: [PATCH] refactor(dev): use `trapUnhandledNodeErrors` utility --- src/runtime/entries/nitro-dev.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/runtime/entries/nitro-dev.ts b/src/runtime/entries/nitro-dev.ts index 327f14fe68..22e67907b3 100644 --- a/src/runtime/entries/nitro-dev.ts +++ b/src/runtime/entries/nitro-dev.ts @@ -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)); @@ -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) {