Browse Source

Fixed websocket.service.ts show error when change error code

pull/15219/head
Vladyslav_Prykhodko 7 months ago
parent
commit
6d127a0f03
  1. 23
      ui-ngx/src/app/core/ws/websocket.service.ts

23
ui-ngx/src/app/core/ws/websocket.service.ts

@ -64,9 +64,10 @@ export abstract class WebsocketService<T extends WsSubscriber> implements WsServ
// This prevents the open→immediately-closed cycle from resetting the counter. // This prevents the open→immediately-closed cycle from resetting the counter.
private reconnectAttempts = 0; private reconnectAttempts = 0;
// Suppress duplicate close-event notifications while retrying. // Stores the last close-event error code shown to the user during a reconnect cycle.
// Set on first close with an error code; cleared after receiving a successful message. // Only suppresses duplicate notifications for the same error code; a new error code is still shown.
private reconnectErrorShown = false; // Cleared after receiving a successful message.
private lastShownCloseCode: number | null = null;
protected constructor(protected store: Store<AppState>, protected constructor(protected store: Store<AppState>,
protected authService: AuthService, protected authService: AuthService,
@ -138,7 +139,7 @@ export abstract class WebsocketService<T extends WsSubscriber> implements WsServ
this.cmdWrapper.clear(); this.cmdWrapper.clear();
if (close) { if (close) {
this.reconnectAttempts = 0; this.reconnectAttempts = 0;
this.reconnectErrorShown = false; this.lastShownCloseCode = null;
this.closeSocket(); this.closeSocket();
} }
} }
@ -236,7 +237,7 @@ export abstract class WebsocketService<T extends WsSubscriber> implements WsServ
this.checkToClose(); this.checkToClose();
if (this.reconnectAttempts) { if (this.reconnectAttempts) {
this.reconnectAttempts = 0; this.reconnectAttempts = 0;
this.reconnectErrorShown = false; this.lastShownCloseCode = null;
} }
} }
@ -248,11 +249,13 @@ export abstract class WebsocketService<T extends WsSubscriber> implements WsServ
} }
private onClose(closeEvent: CloseEvent) { private onClose(closeEvent: CloseEvent) {
// Show error notification only once per reconnect cycle to prevent notification spam. // Show error notification only when the error code changes to prevent notification spam,
// reconnectErrorShown is cleared only after a productive connection (onMessage). // while still surfacing new, potentially actionable errors during a reconnect cycle.
if (!this.reconnectErrorShown && closeEvent && closeEvent.code > 1001 && closeEvent.code !== 1006 // lastShownCloseCode is cleared only after a productive connection (onMessage).
&& closeEvent.code !== 1011 && closeEvent.code !== 1012 && closeEvent.code !== 4500) { if (closeEvent && closeEvent.code > 1001 && closeEvent.code !== 1006
this.reconnectErrorShown = true; && closeEvent.code !== 1011 && closeEvent.code !== 1012 && closeEvent.code !== 4500
&& this.lastShownCloseCode !== closeEvent.code) {
this.lastShownCloseCode = closeEvent.code;
this.showWsError(closeEvent.code, closeEvent.reason); this.showWsError(closeEvent.code, closeEvent.reason);
} }
this.isOpening = false; this.isOpening = false;

Loading…
Cancel
Save