{"record":{"id":"1d588e23ae9f17c9","repo":"jackwener/OpenCLI","slug":"http-result-httpstatus-from-result-where-1d588e","errorCode":null,"errorMessage":"HTTP ${result.httpStatus} from ${result.where}","messagePattern":"HTTP (.+?) from (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/whoami.js","lineNumber":49,"sourceCode":"        if (!res.ok) {\n          return { kind: 'http', httpStatus: res.status, where: '/api/me.json' };\n        }\n        const d = await res.json();\n        const me = d?.data;\n        if (!me?.name) {\n          return { kind: 'auth', detail: 'Not logged in to reddit.com (no identity in /api/me.json)' };\n        }\n        return { kind: 'ok', identity: me };\n      } catch (e) {\n        return { kind: 'exception', detail: String(e && e.message || e) };\n      }\n    })()`);\n\n        if (result?.kind === 'auth') {\n            throw new AuthRequiredError('reddit.com', result.detail);\n        }\n        if (result?.kind === 'http') {\n            throw new CommandExecutionError(`HTTP ${result.httpStatus} from ${result.where}`);\n        }\n        if (result?.kind === 'exception') {\n            throw new CommandExecutionError(`whoami failed: ${result.detail}`);\n        }\n        if (result?.kind !== 'ok') {\n            throw new CommandExecutionError(`Unexpected result from reddit whoami: ${JSON.stringify(result)}`);\n        }\n\n        const u = result.identity;\n        const created = u.created_utc\n            ? new Date(u.created_utc * 1000).toISOString().split('T')[0]\n            : null;\n        const linkKarma = typeof u.link_karma === 'number' ? u.link_karma : null;\n        const commentKarma = typeof u.comment_karma === 'number' ? u.comment_karma : null;\n        const totalKarma = typeof u.total_karma === 'number'\n            ? u.total_karma\n            : (linkKarma != null && commentKarma != null ? linkKarma + commentKarma : null);\n        const inboxCount = typeof u.inbox_count === 'number' ? u.inbox_count : null;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/whoami.js#L31-L67","documentation":"This CommandExecutionError is thrown by the reddit whoami CLI when the internal script executed in the page/binary context reports kind === 'http', meaning the whoami HTTP request completed but Reddit returned a non-success HTTP status (result.httpStatus) from endpoint result.where. The CLI wraps any non-auth HTTP failure as a command execution error so callers see the status code and the URL that failed. It signals the request reached Reddit but was rejected at the transport/status level, not an authentication-cookie problem (that path throws AuthRequiredError instead).","triggerScenarios":"Running the `whoami` command for reddit when the underlying whoami result object has kind='http'; i.e., the request to reddit.com returned a status code outside the success range (e.g., 403, 429, 500, 503) while a valid session cookie was still present.","commonSituations":"Reddit rate-limiting the client (HTTP 429) after rapid repeated whoami calls; Reddit edge/WAF returning 403 for flagged IPs or datacenter egress; transient Reddit 5xx outages; proxy/VPN interfering so requests are blocked with a non-200 status even though the session cookie exists.","solutions":["Read result.httpStatus and result.where from the message to identify which endpoint failed and how, then address that specific status (403 => IP/bot detection, 429 => back off, 5xx => retry later).","Wait and retry with exponential backoff if the status is 429 or 5xx; reduce polling frequency of whoami.","If 403, switch egress IP (disable proxy/VPN or use a residential IP) or clear browser fingerprint flags that trigger Reddit's WAF.","Verify the session is still valid by re-authenticating; an expired-but-present cookie can yield unexpected statuses rather than a clean auth failure.","Catch CommandExecutionError in calling code and surface result.httpStatus to distinguish transient from permanent failures."],"exampleFix":"// before: hammering whoami in a tight loop, hitting 429\nfor (const id of ids) { await whoami(client); }\n\n// after: retry with backoff on transient statuses\nconst res = await withBackoff(() => whoami(client), {\n  retryOn: (e) => /HTTP (429|5\\d\\d) from/.test(e.message)\n});","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isHttpStatusError(e) {\n  return e instanceof CommandExecutionError && /HTTP \\d{3} from /.test(e.message);\n}\nfunction statusOf(e) {\n  const m = e.message.match(/HTTP (\\d{3}) from /);\n  return m ? Number(m[1]) : null;\n}","tryCatchPattern":"try {\n  await whoami();\n} catch (e) {\n  if (isHttpStatusError(e)) {\n    const s = statusOf(e);\n    if (s === 429 || s >= 500) await backoffRetry(whoami, 3);\n    else throw e; // 403 etc. won't fix itself\n  } else throw e;\n}","preventionTips":["Rate-limit whoami calls with a minimum interval to avoid 429s.","Use stable residential egress rather than datacenter IPs to avoid 403 WAF blocks.","Wrap network commands in a backoff-retry helper that only retries 429/5xx.","Log the status code and endpoint (parsed from the message) for monitoring."],"tags":["http","http-status","reddit","cli","network"],"backgroundTag":"http-non-2xx-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}