diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 349d617..ce4ed1c 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -321,6 +321,7 @@ export class WebsocketClient extends EventEmitter { private parseWsError(context: string, error: any, wsKey: WsKey) { if (!error.message) { this.logger.error(`${context} due to unexpected error: `, error); + this.emit('error', error); return; } @@ -339,14 +340,13 @@ export class WebsocketClient extends EventEmitter { ); break; } + this.emit('error', error); } /** * Return params required to make authorized request */ private async getAuthParams(wsKey: WsKey): Promise { - const { key, secret } = this.options; - if (PUBLIC_WS_KEYS.includes(wsKey)) { this.logger.debug('Starting public only websocket client.', { ...loggerCategory, diff --git a/test/inverse/ws.private.test.ts b/test/inverse/ws.private.test.ts index 7a4c325..1c8fb2d 100644 --- a/test/inverse/ws.private.test.ts +++ b/test/inverse/ws.private.test.ts @@ -34,12 +34,11 @@ describe('Private Inverse Perps Websocket Client', () => { badClient.connectPrivate(); - expect(wsOpenPromise).rejects.toMatch('Failed to receive'); - try { - await Promise.all([wsOpenPromise]); + expect(await wsOpenPromise).toMatch('Failed to receive'); } catch (e) { // console.error() + expect(e?.message).toStrictEqual('Unexpected server response: 401'); } badClient.closeAll(); }); diff --git a/test/linear/ws.private.test.ts b/test/linear/ws.private.test.ts index e3b3fe2..8e8cecf 100644 --- a/test/linear/ws.private.test.ts +++ b/test/linear/ws.private.test.ts @@ -34,12 +34,10 @@ describe('Private Linear Perps Websocket Client', () => { badClient.connectPrivate(); - expect(wsOpenPromise).rejects.toMatch('Failed to receive'); - try { - await Promise.all([wsOpenPromise]); + expect(await wsOpenPromise).toMatch('Failed to receive'); } catch (e) { - // console.error() + expect(e?.message).toStrictEqual('Unexpected server response: 401'); } badClient.closeAll(); });