fix(websocket-client): get rid of problematic timeout error emit

This commit is contained in:
Tomas Martykan
2025-03-25 12:17:28 +01:00
committed by martin
parent 4f1b2b73eb
commit b8016dfb2e

View File

@@ -170,9 +170,9 @@ export class WebsocketClient<Events extends Record<string, any>> extends TypedEm
// set connection timeout before WebSocket initialization
const connectionTimeout = setTimeout(
() => {
ws.emit('error', new WebsocketError('websocket_timeout'));
this.onClose();
dfd.reject(new WebsocketError('websocket_timeout'));
try {
ws.once('error', () => {}); // hack; ws throws uncaughtably when there's no error listener
ws.close();
} catch {
// empty
@@ -237,6 +237,9 @@ export class WebsocketClient<Events extends Record<string, any>> extends TypedEm
clearTimeout(this.pingTimeout);
this.ws?.removeAllListeners();
this.ws?.on('error', () => {
// Suppress errors after close
});
this.messages.rejectAll(new WebsocketError('Websocket closed unexpectedly'));
}