(
client: ApiClient,
options?: { timeoutMs?: number }
)
| 99 | } |
| 100 | |
| 101 | export async function checkAuth( |
| 102 | client: ApiClient, |
| 103 | options?: { timeoutMs?: number } |
| 104 | ): Promise<AuthCheckResult> { |
| 105 | const timeoutMs = options?.timeoutMs ?? 1_000; |
| 106 | |
| 107 | try { |
| 108 | // Used both as an auth check and a basic liveness check. |
| 109 | await promiseWithTimeout(client.general.ping("vscode"), timeoutMs, "API ping"); |
| 110 | return { status: "ok" }; |
| 111 | } catch (error) { |
| 112 | if (isUnauthorizedError(error)) { |
| 113 | return { status: "unauthorized", error: formatError(error) }; |
| 114 | } |
| 115 | |
| 116 | return { status: "error", error: formatError(error) }; |
| 117 | } |
| 118 | } |
no test coverage detected