From b7ddb93994ceab8112f8d6911b8d78b862ce940e Mon Sep 17 00:00:00 2001 From: Yusup Hambali Date: Mon, 24 Jul 2023 00:42:55 +0700 Subject: [PATCH 1/2] Set error code `EADDRINUSE` in case conflict port --- src/js/node/http.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/node/http.ts b/src/js/node/http.ts index 2eb5231d58ae..e7476301a832 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -316,6 +316,11 @@ export class Agent extends EventEmitter { function emitListeningNextTick(self, onListen, err, hostname, port) { if (typeof onListen === "function") { try { + if (err?.message.includes(`Is port ${port} in use`)) { + err.code = "EADDRINUSE"; + err.address = hostname; + err.port = port; + } onListen(err, hostname, port); } catch (err) { self.emit("error", err); From 466af9e77b8f12c4febeb4c9ad4313c81f58b38d Mon Sep 17 00:00:00 2001 From: Yusup Hambali Date: Mon, 24 Jul 2023 02:24:46 +0700 Subject: [PATCH 2/2] Update http.ts --- src/js/node/http.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/node/http.ts b/src/js/node/http.ts index e7476301a832..34524d938f4a 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -316,7 +316,7 @@ export class Agent extends EventEmitter { function emitListeningNextTick(self, onListen, err, hostname, port) { if (typeof onListen === "function") { try { - if (err?.message.includes(`Is port ${port} in use`)) { + if (err?.message?.includes(`Is port ${port} in use`)) { err.code = "EADDRINUSE"; err.address = hostname; err.port = port;