Stage 17 #2 fix: connection failures show only the spinner, never a toast
A dropped/reset/timed-out connection can surface as a Connect code other than Unavailable (Canceled/DeadlineExceeded/Unknown/…) which fell through to the generic 'internal' -> a red 'something went wrong' toast appeared alongside the Connecting spinner. Now toGatewayError (moved to the pure retry.ts, unit-tested) collapses every transport-level code to 'unavailable' so it is retried + flips offline; and handleError suppresses the toast for any connection code AND whenever the app is mid-reconnect (!connection.online), covering the race where a unary error lands before the stream reports the drop. Genuine server-internal / domain errors still toast while online.
This commit is contained in:
+10
-13
@@ -23,7 +23,7 @@ import {
|
||||
} from './telegram';
|
||||
import { parseStartParam } from './deeplink';
|
||||
import { clearSession, loadPrefs, loadSession, saveSession, savePrefs } from './session';
|
||||
import { reportOffline, reportOnline, resetConnection } from './connection.svelte';
|
||||
import { connection, reportOffline, reportOnline, resetConnection } from './connection.svelte';
|
||||
import { isConnectionCode } from './retry';
|
||||
import { clearGameCache } from './gamecache';
|
||||
import { clearLobby } from './lobbycache';
|
||||
@@ -115,21 +115,18 @@ export function clearChatUnread(gameId: string): void {
|
||||
if (app.chatUnread[gameId]) app.chatUnread = { ...app.chatUnread, [gameId]: 0 };
|
||||
}
|
||||
|
||||
/** handleError maps a GatewayError to a toast; an invalid session logs out. */
|
||||
/** handleError maps a GatewayError to a toast; an invalid session logs out. A connectivity
|
||||
* failure — or anything raised while the app is mid-reconnect — is shown by the "Connecting…"
|
||||
* header indicator (and auto-retried), never a red toast. */
|
||||
export function handleError(err: unknown): void {
|
||||
telegramHaptic('error');
|
||||
if (err instanceof GatewayError) {
|
||||
if (err.code === 'session_invalid' || err.code === 'unauthenticated') {
|
||||
void logout();
|
||||
return;
|
||||
}
|
||||
// A connectivity failure is shown by the "Connecting…" header indicator (and auto-retried),
|
||||
// not a red toast on every attempt.
|
||||
if (isConnectionCode(err.code)) return;
|
||||
showToast(t(errorKey(err.code)), 'error');
|
||||
const code = err instanceof GatewayError ? err.code : '';
|
||||
if (code === 'session_invalid' || code === 'unauthenticated') {
|
||||
void logout();
|
||||
return;
|
||||
}
|
||||
showToast(t('error.generic'), 'error');
|
||||
if (isConnectionCode(code) || !connection.online) return;
|
||||
telegramHaptic('error');
|
||||
showToast(t(code ? errorKey(code) : 'error.generic'), 'error');
|
||||
}
|
||||
|
||||
function openStream(): void {
|
||||
|
||||
Reference in New Issue
Block a user