The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { ManagedRelay, relayRequestFailureDetail } from "@t3tools/client-runtime/relay"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | import { msg } from "gt-react"; |
| 4 | |
| 5 | import { m } from "../i18n/messages"; |
| 6 | |
| 7 | const isRequestFailed = Schema.is(ManagedRelay.ManagedRelayRequestFailedError); |
| 8 | const isRequestTimeout = Schema.is(ManagedRelay.ManagedRelayRequestTimeoutError); |
| 9 | |
| 10 | /** One short line for an error toast saying why a T3 Connect request failed. */ |
| 11 | export function relayFailureReason(cause: unknown): string | null { |
| 12 | for (let current = cause, depth = 0; current instanceof Error && depth < 4; depth += 1) { |
| 13 | if (isRequestTimeout(current)) return m(msg("T3 Connect timed out. Try again.")); |
| 14 | if (isRequestFailed(current)) { |
| 15 | if (current.transportFailed) return m(msg("Could not reach T3 Connect. Check your network.")); |
| 16 | if (current.relayError) { |
| 17 | return current.relayError._tag === "RelayInternalError" |
| 18 | ? m(msg("T3 Connect is unavailable. Try again.")) |
| 19 | : relayRequestFailureDetail(current); |
| 20 | } |
| 21 | if (current.status === 504) return m(msg("T3 Connect timed out. Try again.")); |
| 22 | if ((current.status ?? 0) >= 500) return m(msg("T3 Connect is unavailable. Try again.")); |
| 23 | return relayRequestFailureDetail(current); |
| 24 | } |
| 25 | current = current.cause; |
| 26 | } |
| 27 | return null; |
| 28 | } |