From 5a377dffa5fd68d09b047303c7833fc700a7f902 Mon Sep 17 00:00:00 2001 From: busya Date: Tue, 2 Jun 2026 14:37:53 +0300 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20add=20WebSocket=20debug=20logg?= =?UTF-8?q?ing=20=E2=80=94=20silent=20failures=20now=20visible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- frontend/src/lib/stores/translationRun.svelte.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/stores/translationRun.svelte.ts b/frontend/src/lib/stores/translationRun.svelte.ts index 6d403134..ff82332d 100644 --- a/frontend/src/lib/stores/translationRun.svelte.ts +++ b/frontend/src/lib/stores/translationRun.svelte.ts @@ -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; @@ -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; } }