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

transportError.ts

34 lines1.1 KB

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