MCPcopy Index your code
hub / github.com/coder/mux / checkServerReachable

Function checkServerReachable

vscode/src/api/connectionCheck.ts:62–99  ·  view source on GitHub ↗
(
  baseUrl: string,
  options?: { timeoutMs?: number }
)

Source from the content-addressed store, hash-verified

60}
61
62export async function checkServerReachable(
63 baseUrl: string,
64 options?: { timeoutMs?: number }
65): Promise<ServerReachabilityResult> {
66 const timeoutMs = options?.timeoutMs ?? 1_000;
67 const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
68
69 const controller = new AbortController();
70 const timeout = setTimeout(() => controller.abort(), timeoutMs);
71
72 try {
73 const resp = await fetch(`${normalizedBaseUrl}/health`, {
74 method: "GET",
75 signal: controller.signal,
76 });
77
78 if (!resp.ok) {
79 return { status: "unreachable", error: `HTTP ${resp.status} from /health` };
80 }
81
82 const data = (await resp.json()) as { status?: unknown };
83 if (data.status !== "ok") {
84 return {
85 status: "unreachable",
86 error: "Unexpected /health response",
87 };
88 }
89
90 return { status: "ok" };
91 } catch (error) {
92 return {
93 status: "unreachable",
94 error: formatError(error),
95 };
96 } finally {
97 clearTimeout(timeout);
98 }
99}
100
101export async function checkAuth(
102 client: ApiClient,

Callers 3

tryGetApiClientFunction · 0.90
debugConnectionCommandFunction · 0.90

Calls 4

normalizeBaseUrlFunction · 0.70
fetchFunction · 0.70
formatErrorFunction · 0.70
abortMethod · 0.65

Tested by

no test coverage detected