From 69976e80d7b761a72479f5b942f1c7d6a4582aec Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 28 Jan 2021 15:16:53 -0500 Subject: [PATCH] give user a friendlier error when address() is unavailable due to noServer --- server.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index c705e7f..e490d7a 100644 --- a/server.js +++ b/server.js @@ -120,11 +120,14 @@ class Server extends EventEmitter { clientTracking: false, ...(isObject(opts.ws) ? opts.ws : undefined) }) - if (!noServer) { - this.ws.address = () => { - return this.http.address() + + this.ws.address = () => { + if (noServer) { + throw new Error('address() unavailable with { noServer: true }') } + return this.http.address() } + this.ws.on('error', err => { this._onError(err) }) this.ws.on('connection', (socket, req) => { // Note: socket.upgradeReq was removed in ws@3.0.0, so re-add it.