From 2d221aac14825090f9c081f48b71c11533ec572a Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Mon, 19 Sep 2022 00:13:11 +0100 Subject: [PATCH] error event from ws client --- src/websocket-client.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 4a0e52c..062dae2 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -41,7 +41,7 @@ export type WsClientEvent = | 'open' | 'update' | 'close' - | 'errorEvent' + | 'error' | 'reconnect' | 'reconnected' | 'response'; @@ -53,7 +53,7 @@ interface WebsocketClientEvents { close: (evt: { wsKey: WsKey; event: any }) => void; response: (response: any) => void; update: (response: any) => void; - errorEvent: (response: any) => void; + error: (response: any) => void; } // Type safety for on and emit handlers: https://stackoverflow.com/a/61609010/880837 @@ -344,7 +344,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('errorEvent', error); + this.emit('error', error); return; } @@ -365,7 +365,7 @@ export class WebsocketClient extends EventEmitter { ); break; } - this.emit('errorEvent', error); + this.emit('error', error); } /** @@ -663,7 +663,7 @@ export class WebsocketClient extends EventEmitter { // usdc options msg?.success === false ) { - return this.emit('errorEvent', { ...msg, wsKey }); + return this.emit('error', { ...msg, wsKey }); } this.logger.warning('Unhandled/unrecognised ws event message', { @@ -684,11 +684,6 @@ export class WebsocketClient extends EventEmitter { private onWsError(error: any, wsKey: WsKey) { this.parseWsError('Websocket error', error, wsKey); - if ( - this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTED) - ) { - this.emit('errorEvent', error); - } } private onWsClose(event, wsKey: WsKey) {