{"record":{"id":"8b944c6272003fe2","repo":"jackwener/OpenCLI","slug":"label-failed-http-response-status","errorCode":null,"errorMessage":"${label} failed: HTTP ${response.status}","messagePattern":"(.+?) failed: HTTP (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/user-id.js","lineNumber":28,"sourceCode":"    return `\n  function normalizeInstagramUserId(value, label) {\n    const id = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');\n    if (!/^\\\\d+$/.test(id)) throw new Error(label);\n    return id;\n  }\n  async function readInstagramJson(response, label) {\n    try {\n      return await response.json();\n    } catch {\n      throw new Error(label + ' returned invalid JSON');\n    }\n  }\n  function throwInstagramHttpError(response, label, username) {\n    if (response.status === 404) throw new Error('User not found: ' + username);\n    if (response.status === 401 || response.status === 403) {\n      throw new Error('HTTP ' + response.status + ' - make sure you are logged in to Instagram');\n    }\n    throw new Error(label + ' failed: HTTP ' + response.status);\n  }\n  const r1 = await fetch('https://www.instagram.com/api/v1/users/web_profile_info/?username=' + encodeURIComponent(username), opts);\n  if (r1.status === 404) throw new Error('User not found: ' + username);\n  if (!r1.ok && r1.status !== 400) throwInstagramHttpError(r1, 'Instagram web_profile_info', username);\n  let userId = r1.ok ? normalizeInstagramUserId((await readInstagramJson(r1, 'Instagram web_profile_info'))?.data?.user?.id, 'Instagram web_profile_info returned no valid user id for: ' + username) : '';\n  if (!userId) {\n    const r1b = await fetch('https://www.instagram.com/api/v1/feed/user/' + encodeURIComponent(username) + '/username/?count=1', opts);\n    if (!r1b.ok) throwInstagramHttpError(r1b, 'Instagram feed-by-username', username);\n    userId = normalizeInstagramUserId((await readInstagramJson(r1b, 'Instagram feed-by-username'))?.user?.pk, 'Instagram feed returned no valid profile owner for: ' + username);\n  }`;\n}\n","sourceCodeStart":10,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/user-id.js#L10-L40","documentation":"Generic HTTP failure path of throwInstagramHttpError: the Instagram API endpoint (label names which one, e.g. 'Instagram web_profile_info' or 'Instagram feed-by-username') returned a status that is not 404 (user-not-found) or 401/403 (auth). The library throws it as a catch-all for unexpected server responses like 429 (rate limit) or 5xx errors. The label in the message tells you which of the two fallback endpoints failed.","triggerScenarios":"The fetch in buildResolveInstagramUserIdJs gets a response with an unhandled status — most commonly HTTP 429 (rate limited) or 5xx from web_profile_info, or a non-ok status from the feed-by-username fallback — and the error propagates out of the in-page script.","commonSituations":"Resolving many usernames in a row and hitting Instagram's rate limits (429); Instagram having a transient outage (5xx); a proxy/VPN or corporate network returning an unexpected status; Instagram A/B changes to endpoint behavior returning a new status code.","solutions":["Read the HTTP status in the message: 429 means back off — wait several minutes before retrying","For 5xx, retry after a short delay; it is usually transient on Instagram's side","Slow down batch usage: add delays between username lookups to avoid rate limiting","Disable VPN/proxy that may interfere, or retry from a different network","If a specific status persists, check whether Instagram changed the API and update the CLI"],"exampleFix":"// before: rapid-fire lookups causing 429\nfor (const u of users) await getUserId(u); // Error: Instagram web_profile_info failed: HTTP 429\n\n// after: throttle lookups\nfor (const u of users) {\n  await getUserId(u);\n  await new Promise(r => setTimeout(r, 3000));\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await resolveInstagramUserId(username);\n} catch (e) {\n  const m = e.message.match(/failed: HTTP (\\d+)/);\n  if (m && (m[1] === '429' || m[1].startsWith('5'))) {\n    await sleep(m[1] === '429' ? 120000 : 5000);\n    return resolveInstagramUserId(username); // retry once with backoff\n  }\n  throw e;\n}","preventionTips":["Throttle username lookups (add delays) to avoid 429 rate limits","Back off exponentially on 5xx responses instead of hammering the API","Distinguish 404/401/403 (not retryable) from 429/5xx (retryable) in your error handling","Avoid VPNs/proxies that can inject unexpected HTTP responses"],"tags":["http-error","rate-limit","instagram","network"],"backgroundTag":"http-unexpected-status","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}