upstash/context7 · error

Failed to fetch user info

Error message

Failed to fetch user info

What it means

Generic Error thrown by fetchWhoami when the whoami endpoint returns any non-OK status other than 401. It indicates the server failed to return user info for a reason other than an expired session, such as a server-side fault or an unexpected response. The whoami command catches it and suggests retrying later.

Solutions

  1. Retry the command after a short wait; the failure is often transient server-side.
  2. Check the Context7 API status / your network connectivity.
  3. Verify getBaseUrl() resolves to the correct API endpoint (check env/config overrides).
  4. If a proxy is in use, confirm it passes through requests to the API host.

Example fix

// before
curl https://wrong-host.example.com/api/dashboard/whoami  # 502

// after (correct base URL)
curl https://context7.com/api/dashboard/whoami -H "Authorization: Bearer $TOKEN"
Defensive patterns

Strategy: retry

Validate before calling

const url = getBaseUrl();
new URL(url); // fail fast on misconfigured base URL
if (!navigator.onLine) throw new Error('Offline');

Try / catch

try {
  const whoami = await fetchWhoami(token);
} catch (e) {
  if (!(e instanceof SessionRejectedError)) {
    await delay(1000); // then retry, or surface 'try again later'
  }
}

Prevention

When it happens

Trigger: fetchWhoami(accessToken) is called and `fetch(`${getBaseUrl()}/api/dashboard/whoami`)` responds with a status that is neither 200-299 nor 401 (e.g. 500, 502, 503).

Common situations: Context7 API outage or maintenance; a proxy or corporate firewall returning 502/503; misconfigured custom base URL hitting a non-Context7 server; rate limiting (429).

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16). Data as JSON: /api/errors/f85bbe67ca9b9329. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/commands/auth.ts:275

  name: string | null;
  email: string | null;
  teamspace: { id: string; name: string } | null;
}

class SessionRejectedError extends Error {}

async function fetchWhoami(accessToken: string): Promise<WhoamiResponse> {
  const response = await fetch(`${getBaseUrl()}/api/dashboard/whoami`, {
    headers: {
      Authorization: `Bearer ${accessToken}`,
    },
  });

  if (response.status === 401) {
    throw new SessionRejectedError("Session was rejected by the server");
  }
  if (!response.ok) {
    throw new Error("Failed to fetch user info");
  }

  return (await response.json()) as WhoamiResponse;
}

View on GitHub (pinned to 4416fb855b)