error event from ws client

This commit is contained in:
tiagosiebler
2022-09-19 00:13:11 +01:00
parent 5894e45393
commit 2d221aac14

View File

@@ -41,7 +41,7 @@ export type WsClientEvent =
| 'open' | 'open'
| 'update' | 'update'
| 'close' | 'close'
| 'errorEvent' | 'error'
| 'reconnect' | 'reconnect'
| 'reconnected' | 'reconnected'
| 'response'; | 'response';
@@ -53,7 +53,7 @@ interface WebsocketClientEvents {
close: (evt: { wsKey: WsKey; event: any }) => void; close: (evt: { wsKey: WsKey; event: any }) => void;
response: (response: any) => void; response: (response: any) => void;
update: (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 // 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) { private parseWsError(context: string, error: any, wsKey: WsKey) {
if (!error.message) { if (!error.message) {
this.logger.error(`${context} due to unexpected error: `, error); this.logger.error(`${context} due to unexpected error: `, error);
this.emit('errorEvent', error); this.emit('error', error);
return; return;
} }
@@ -365,7 +365,7 @@ export class WebsocketClient extends EventEmitter {
); );
break; break;
} }
this.emit('errorEvent', error); this.emit('error', error);
} }
/** /**
@@ -663,7 +663,7 @@ export class WebsocketClient extends EventEmitter {
// usdc options // usdc options
msg?.success === false msg?.success === false
) { ) {
return this.emit('errorEvent', { ...msg, wsKey }); return this.emit('error', { ...msg, wsKey });
} }
this.logger.warning('Unhandled/unrecognised ws event message', { this.logger.warning('Unhandled/unrecognised ws event message', {
@@ -684,11 +684,6 @@ export class WebsocketClient extends EventEmitter {
private onWsError(error: any, wsKey: WsKey) { private onWsError(error: any, wsKey: WsKey) {
this.parseWsError('Websocket error', error, wsKey); this.parseWsError('Websocket error', error, wsKey);
if (
this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTED)
) {
this.emit('errorEvent', error);
}
} }
private onWsClose(event, wsKey: WsKey) { private onWsClose(event, wsKey: WsKey) {