{"record":{"id":"a5c4660da9e6ad4d","repo":"jackwener/OpenCLI","slug":"http-result-httpstatus-from-api-organizations","errorCode":null,"errorMessage":"HTTP ${result.httpStatus} from /api/organizations","messagePattern":"HTTP (.+?) from /api/organizations","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/claude/auth.js","lineNumber":35,"sourceCode":"      const res = await fetch('/api/organizations', { credentials: 'include' });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Claude /api/organizations HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (!Array.isArray(d) || d.length === 0) {\n        return { kind: 'auth', detail: 'Claude /api/organizations empty' };\n      }\n      const userIdCookie = (document.cookie.split('; ').find(c => c.startsWith('ajs_user_id=')) || '').split('=')[1] || '';\n      const activeOrgCookie = (document.cookie.split('; ').find(c => c.startsWith('lastActiveOrg=')) || '').split('=')[1] || '';\n      const activeOrg = d.find(o => o.uuid === activeOrgCookie) || d[0];\n      return { ok: true, user_id: userIdCookie, org_name: activeOrg.name || '', org_uuid: activeOrg.uuid || '' };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('claude.ai', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/organizations`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Claude whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Claude probe: ${JSON.stringify(result)}`);\n  if (!result.user_id) throw new AuthRequiredError('claude.ai', 'Claude session incomplete — ajs_user_id cookie missing');\n  return { user_id: String(result.user_id), org_name: String(result.org_name), org_uuid: String(result.org_uuid) };\n}\n\nregisterSiteAuthCommands({\n  site: 'claude',\n  domain: 'claude.ai',\n  loginUrl: 'https://claude.ai/login',\n  columns: ['user_id', 'org_name', 'org_uuid'],\n  quickCheck: hasClaudeSessionCookie,\n  verify: verifyClaudeIdentity,\n  poll: async (page) => {\n    if (!await hasClaudeSessionCookie(page)) {\n      throw new AuthRequiredError('claude.ai', 'Waiting for Claude sessionKey cookie');\n    }\n    return verifyClaudeIdentity(page);","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/claude/auth.js#L17-L53","documentation":"This CommandExecutionError is thrown by verifyClaudeIdentity when the in-page fetch to https://claude.ai/api/organizations returns a non-OK, non-401/403 status (result.kind === 'http'). The library probes this endpoint after confirming a sessionKey cookie exists, to resolve the user's org identity; any other HTTP failure status (e.g. 429, 5xx) surfaces here. It means the Claude session cookie was present but the API call itself failed.","triggerScenarios":"The sessionKey cookie exists but the /api/organizations request returns a status other than 200/401/403 — e.g. HTTP 429 rate limiting, 402 (billing/quota), 500/502/503 server errors, or 404 if Claude changes the endpoint path.","commonSituations":"Hitting Claude's API rate limits after repeated probes; transient Cloudflare or backend outages on claude.ai; Claude API returning an unusual status (e.g. 402 for disabled accounts); corporate proxies intercepting requests; Claude renaming/moving the /api/organizations endpoint in a frontend update.","solutions":["Wait 30-60 seconds and re-run the command — most 429/5xx statuses are transient","Re-run `opencli claude auth` (or the site auth flow) to refresh the session and re-probe","Check https://claude.ai loads normally in the browser to rule out a Claude outage or account billing issue","Clear claude.ai cookies, log in fresh, and retry so a stale/corrupt session is not causing odd responses","Update the library in case Claude changed the endpoint and a newer version probes a different URL"],"exampleFix":"// before\nopencli claude whoami   // -> HTTP 429 from /api/organizations\n// after\nsleep 60 && opencli claude whoami   // retry after rate-limit window passes","handlingStrategy":"retry","validationCode":"// pre-check session health before relying on whoami\nconst cookies = await page.getCookies({ url: 'https://claude.ai' });\nif (!cookies.some(c => c.name === 'sessionKey' && c.value)) {\n  throw new Error('Run `opencli claude auth` first — no sessionKey cookie');\n}","typeGuard":"function isHttpFailure(result) {\n  return result && result.kind === 'http' && Number.isInteger(result.httpStatus) && !(result.httpStatus >= 200 && result.httpStatus < 400);\n}","tryCatchPattern":"try {\n  const identity = await verifyClaudeIdentity(page);\n} catch (e) {\n  if (/HTTP \\d+ from \\/api\\/organizations/.test(e.message)) {\n    await sleep(60000);           // back off for rate limits / 5xx\n    return verifyClaudeIdentity(page);\n  }\n  throw e;\n}","preventionTips":["Retry with backoff on 429/5xx instead of failing immediately","Check https://status.anthropic.com or claude.ai availability before batch runs","Refresh the session via `opencli claude auth` if errors persist across retries","Keep the library updated in case Claude changes the probe endpoint"],"tags":["http","claude","network","api"],"backgroundTag":"http-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}