From b3465ea96d236210d212232b1dd34ac16af80af4 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Sun, 16 Aug 2020 12:33:16 +0200 Subject: [PATCH] Catching websocket errors to not take down whole process --- src/websocket.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/websocket.ts b/src/websocket.ts index f559230..eb4a71f 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -22,6 +22,12 @@ export class WebsocketConnectionManager { private static async onConnection(socket: WebSocket, req: IncomingMessage) { Logging.log("New Connection:"); + + socket.on("error", (err) => { + Logging.error(err); + socket.close(); + }); + const sendError = (error: string) => socket.send(JSON.stringify({ ns: "error_msg", data: error }));