{"record":{"id":"c658185d57104a13","repo":"jackwener/OpenCLI","slug":"label-failed-http-response-status-c65818","errorCode":null,"errorMessage":"${label} failed: HTTP ${response.status}","messagePattern":"(.+?) failed: HTTP (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/instagram/profile.js","lineNumber":34,"sourceCode":"  const opts = { credentials: 'include', headers: { 'X-IG-App-ID': '936619743392459' } };\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) {\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  function mapProfileUser(u, countFields) {\n    if (!u || typeof u !== 'object' || typeof u.username !== 'string' || !u.username.trim()) {\n      throw new Error('Instagram profile returned malformed user payload for: ' + username);\n    }\n    return {\n      username: u.username,\n      name: typeof u.full_name === 'string' ? u.full_name : '',\n      bio: (typeof u.biography === 'string' ? u.biography : '').replace(/\\\\n/g, ' ').substring(0, 120),\n      followers: countFields.followers(u),\n      following: countFields.following(u),\n      posts: countFields.posts(u),\n      verified: u.is_verified ? 'Yes' : 'No',\n    };\n  }\n  const r1 = await fetch(\n    'https://www.instagram.com/api/v1/users/web_profile_info/?username=' + encodeURIComponent(username),\n    opts","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/profile.js#L16-L52","documentation":"Generic HTTP-failure branch of throwInstagramHttpError in profile.js: any non-OK status from the profile endpoints that is not 404/401/403 becomes '<label> failed: HTTP <status>'. Label identifies the endpoint (Instagram web_profile_info, feed-by-username, or users info).","triggerScenarios":"clis/instagram/profile receives 429 (rate limit), 5xx (Instagram outage), or other unexpected statuses from web_profile_info, feed/user/.../username, or users/<id>/info endpoints.","commonSituations":"Rate limiting after many rapid profile queries (429); Instagram server incidents (500/502/503); blocked client from too much automation; transient network middleboxes returning odd statuses.","solutions":["Check the status code: 429 means back off and retry with exponential delay; 5xx means retry later","Reduce request frequency / add delays between profile lookups to avoid 429","Verify the session and X-IG-App-ID header are being sent (Instagram may 4xx without it)","Check Instagram status/community reports if 5xx persists","Update the CLI if Instagram changed endpoint requirements (new headers required)"],"exampleFix":"// before: single attempt, immediate throw\nconst r1 = await fetch(url, opts);\nif (!r1.ok && r1.status !== 400) throwInstagramHttpError(r1, 'Instagram web_profile_info');\n// after: retry 429/5xx with backoff\nlet r1 = await fetch(url, opts);\nfor (let i = 0; i < 3 && (r1.status === 429 || r1.status >= 500); i++) {\n  await new Promise((res) => setTimeout(res, 2000 * 2 ** i));\n  r1 = await fetch(url, opts);\n}\nif (!r1.ok && r1.status !== 400) throwInstagramHttpError(r1, 'Instagram web_profile_info');","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isRetryableStatus(status) {\n  return status === 429 || status === 408 || (status >= 500 && status <= 599);\n}","tryCatchPattern":"try {\n  const profile = await instagramProfile(username);\n} catch (e) {\n  const m = /failed: HTTP (\\d+)/.exec(e.message || '');\n  if (m && (m[1] === '429' || m[1].startsWith('5'))) {\n    await sleep(exponentialBackoff(attempt));\n    return retryWithLimit(attempt + 1, 3);\n  }\n  throw e;\n}","preventionTips":["Throttle profile lookups (add delays/jitter between requests) to avoid 429","Implement exponential backoff with a retry cap for 429/5xx","Monitor Instagram status during outages instead of hammering retries","Send the X-IG-App-ID header on every request to avoid spurious 4xx"],"tags":["instagram","http","rate-limit","network"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}