Open History to see the last commit
1import {
2 connectionErrorText,
3 connectionStatusText,
4 type EnvironmentConnectionPresentation,
5} from "@t3tools/client-runtime/connection";
6import type { MarkedText } from "@t3tools/client-runtime/errors";
7
8import { m, type MessageResolver } from "../../i18n/messages";
9
10/** Connection error text from runtime state, in the current language when the error is marked. */
11export function runtimeConnectionErrorText(
12 state: { readonly connectionError: string | null; readonly i18nConnectionError?: MarkedText },
13 resolve: MessageResolver = m,
14): string | null {
15 return connectionErrorText(
16 {
17 error: state.connectionError,
18 ...(state.i18nConnectionError === undefined ? {} : { i18nError: state.i18nConnectionError }),
19 },
20 resolve,
21 );
22}
23
24export function environmentStatusText(
25 connection: EnvironmentConnectionPresentation,
26 resolve: MessageResolver = m,
27): string {
28 const error = connectionErrorText(connection, resolve);
29 return connection.phase === "unsupported" && error !== null
30 ? error
31 : connectionStatusText(connection, resolve);
32}