{"record":{"id":"f85bbe67ca9b9329","repo":"upstash/context7","slug":"failed-to-fetch-user-info","errorCode":null,"errorMessage":"Failed to fetch user info","messagePattern":"Failed to fetch user info","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/auth.ts","lineNumber":275,"sourceCode":"  name: string | null;\n  email: string | null;\n  teamspace: { id: string; name: string } | null;\n}\n\nclass SessionRejectedError extends Error {}\n\nasync function fetchWhoami(accessToken: string): Promise<WhoamiResponse> {\n  const response = await fetch(`${getBaseUrl()}/api/dashboard/whoami`, {\n    headers: {\n      Authorization: `Bearer ${accessToken}`,\n    },\n  });\n\n  if (response.status === 401) {\n    throw new SessionRejectedError(\"Session was rejected by the server\");\n  }\n  if (!response.ok) {\n    throw new Error(\"Failed to fetch user info\");\n  }\n\n  return (await response.json()) as WhoamiResponse;\n}\n","sourceCodeStart":257,"sourceCodeEnd":280,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/commands/auth.ts#L257-L280","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Retry the command after a short wait; the failure is often transient server-side.","Check the Context7 API status / your network connectivity.","Verify getBaseUrl() resolves to the correct API endpoint (check env/config overrides).","If a proxy is in use, confirm it passes through requests to the API host."],"exampleFix":"// before\ncurl https://wrong-host.example.com/api/dashboard/whoami  # 502\n\n// after (correct base URL)\ncurl https://context7.com/api/dashboard/whoami -H \"Authorization: Bearer $TOKEN\"","handlingStrategy":"retry","validationCode":"const url = getBaseUrl();\nnew URL(url); // fail fast on misconfigured base URL\nif (!navigator.onLine) throw new Error('Offline');","typeGuard":null,"tryCatchPattern":"try {\n  const whoami = await fetchWhoami(token);\n} catch (e) {\n  if (!(e instanceof SessionRejectedError)) {\n    await delay(1000); // then retry, or surface 'try again later'\n  }\n}","preventionTips":["Check the API status page during outages before debugging locally.","Pin and verify the base URL configuration; avoid ad-hoc env overrides.","Add retry with backoff for 5xx/429 responses in scripts."],"tags":["network","http","api","cli"],"backgroundTag":"http-error-response","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}