fix(frontend): add WebSocket debug logging — silent failures now visible

Before: _connectWebSocket swallowed all errors silently.
- onerror → silent null
- onclose → silent null
- catch → silent null

Now:
- onopen: console.debug with runId
- onerror: console.warn — fallback to polling
- onclose: console.debug with code/reason
- catch: console.warn with error string

This helps diagnose WS auth failures (wrong token, CORS, etc.)
vs successful WS connections in browser console.
This commit is contained in:
2026-06-02 14:37:53 +03:00
parent 2ec96a5af9
commit 5a377dffa5

View File

@@ -143,6 +143,10 @@ function _connectWebSocket(runId: string): void {
const wsUrl = getTranslateRunWsUrl(runId);
_ws = new WebSocket(wsUrl);
_ws.onopen = () => {
console.debug('[translate:ws] connected', { runId });
};
_ws.onmessage = (event: MessageEvent) => {
try {
const data = JSON.parse(event.data) as Record<string, unknown>;
@@ -185,13 +189,16 @@ function _connectWebSocket(runId: string): void {
};
_ws.onerror = () => {
console.warn('[translate:ws] connection error — falling back to polling', { runId });
_ws = null;
};
_ws.onclose = () => {
_ws.onclose = (event: CloseEvent) => {
console.debug('[translate:ws] closed', { runId, code: event.code, reason: event.reason });
_ws = null;
};
} catch (_e) {
console.warn('[translate:ws] failed to create WebSocket', { runId, error: String(_e) });
_ws = null;
}
}