Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

transportError.ts

33 lines1.1 KB

1const TRANSPORT_ERROR_PATTERNS = [
2 /\bSocketCloseError\b/i,
3 /\bSocketOpenError\b/i,
4 /Unable to connect to the T3 server WebSocket\./i,
5 /\bping timeout\b/i,
6] as const;
7​
8/**
9 * Test whether an error message originates from a transport-level connection
10 * failure (socket close, socket open, ping timeout, etc.) rather than a
11 * business-logic error.
12 */
13export function isTransportConnectionErrorMessage(message: string | null | undefined): boolean {
14 if (typeof message !== "string") {
15 return false;
16 }
17​
18 const normalizedMessage = message.trim();
19 if (normalizedMessage.length === 0) {
20 return false;
21 }
22​
23 return TRANSPORT_ERROR_PATTERNS.some((pattern) => pattern.test(normalizedMessage));
25​
26/**
27 * Strip transport connection errors from user-facing error messages.
28 * Returns `null` for transport errors so the UI can distinguish between
29 * real errors and transient connection issues.
30 */
31export function sanitizeThreadErrorMessage(message: string | null | undefined): string | null {
32 return isTransportConnectionErrorMessage(message) ? null : (message ?? null);