39 lines · 1.3 KB · TypeScript
RawDownload
const TRANSPORT_ERROR_PATTERNS = [  /\bSocketCloseError\b/i,  /\bSocketOpenError\b/i,  /\bSocket is not connected\b/i,  /Unable to connect to the T3 server WebSocket\./i,  /\bis not connected\.$/i,  /\bdisconnected\.$/i,  /\bcould not establish a WebSocket connection\.$/i,  /\bClientProtocolError\b/i,  /\bRpcClientError\b/i,  /\bping timeout\b/i,] as const; /** * Check whether an error message originates from a transport-level connection * failure (socket close, socket open, ping timeout, etc.) rather than a * business-logic error. */export function isTransportConnectionErrorMessage(message: string | null | undefined): boolean {  if (typeof message !== "string") {    return false;  }   const normalizedMessage = message.trim();  if (normalizedMessage.length === 0) {    return false;  }   return TRANSPORT_ERROR_PATTERNS.some((pattern) => pattern.test(normalizedMessage));} /** * Strip transport connection errors from user-facing error messages. * Returns `null` for transport errors so the UI can distinguish between * real errors and transient connection issues. */export function sanitizeThreadErrorMessage(message: string | null | undefined): string | null {  return isTransportConnectionErrorMessage(message) ? null : (message ?? null);}