From 5624ecf96c8a638ce8821d5755892232acfceff1 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sun, 12 Dec 2021 11:18:21 +0530 Subject: [PATCH] fix: throw connection closed instead of WS error --- src/Socket/socket.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index c09459e..428b103 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -68,9 +68,12 @@ export const makeSocket = ({ const sendPromise = promisify(ws.send) /** send a raw buffer */ - const sendRawMessage = (data: Buffer | Uint8Array) => { + const sendRawMessage = async(data: Buffer | Uint8Array) => { + if(ws.readyState !== ws.OPEN) { + throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }) + } const bytes = noise.encodeFrame(data) - return sendPromise.call(ws, bytes) as Promise + await sendPromise.call(ws, bytes) as Promise } /** send a binary node */ const sendNode = (node: BinaryNode) => {