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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user