{"record":{"id":"567e3a4cbd419d85","repo":"jackwener/OpenCLI","slug":"instagram-returned-non-ok-status-json-stringify","errorCode":null,"errorMessage":"Instagram returned non-ok status: ${JSON.stringify(d).slice(0, 300)}","messagePattern":"Instagram returned non-ok status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/collection-create.js","lineNumber":47,"sourceCode":"  const fd = new FormData();\n  fd.append('name', trimmed);\n  fd.append('module_name', 'collection_create');\n  const res = await fetch('https://www.instagram.com/api/v1/collections/create/', {\n    method: 'POST',\n    credentials: 'include',\n    headers: {\n      'X-IG-App-ID': '936619743392459',\n      'X-CSRFToken': csrf,\n    },\n    body: fd,\n  });\n  if (!res.ok) {\n    const body = await res.text().catch(() => '');\n    throw new Error('Failed to create collection: HTTP ' + res.status + (body ? ' - ' + body.slice(0, 200) : ''));\n  }\n  const d = await res.json();\n  if (d?.status && d.status !== 'ok') {\n    throw new Error('Instagram returned non-ok status: ' + JSON.stringify(d).slice(0, 300));\n  }\n  return [{\n    status: 'Created',\n    collectionId: String(d?.collection_id ?? ''),\n    collectionName: String(d?.collection_name ?? trimmed),\n    mediaCount: d?.collection_media_count ?? 0,\n  }];\n})()\n` },\n    ],\n});\n","sourceCodeStart":29,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-create.js#L29-L59","documentation":"Thrown when the create endpoint responds HTTP 200 but the JSON body's status field is present and not 'ok'. Instagram's private API signals logical failures (validation, spam detection, server-side issues) inside a 200 envelope, so this check catches those. The raw JSON is included truncated to 300 chars.","triggerScenarios":"Instagram returns {status: 'fail', ...} for the create request — e.g. server-side rejection of the collection name, suspected automation, or partial service degradation despite HTTP 200.","commonSituations":"Automated collection creation flagged by Instagram anti-bot systems; transient Instagram API issues; payload accepted at HTTP layer but rejected logically.","solutions":["Inspect the included JSON for Instagram's message field","Retry later if it looks like transient Instagram-side degradation","Slow down request rate / add jitter to avoid automation detection","Ensure the collection name doesn't contain characters Instagram rejects"],"exampleFix":"// before\nif (d?.status && d.status !== 'ok') throw new Error('Instagram returned non-ok status: ' + ...);\n// after\nif (d?.status && d.status !== 'ok') {\n  if (d.message === 'please_wait_a_few_minutes') await sleep(120000); // transient\n  throw new Error('Instagram returned non-ok status: ' + ...);\n}","handlingStrategy":"try-catch","validationCode":"// No pre-call validation possible; validate response shape after call\nfunction isOkStatus(d) { return d && d.status === 'ok'; }","typeGuard":"interface IgResponse { status?: string; message?: string }\nfunction hasOkStatus(d: unknown): d is IgResponse & { status: 'ok' } {\n  return typeof d === 'object' && d !== null && (d as IgResponse).status === 'ok';\n}","tryCatchPattern":"try {\n  await createCollection(name);\n} catch (e) {\n  if (String(e.message).startsWith('Instagram returned non-ok status')) {\n    console.warn('Instagram logical failure, retry later:', e.message);\n    return; // or schedule retry\n  }\n  throw e;\n}","preventionTips":["Slow down automation to avoid Instagram anti-bot flags","Inspect the embedded JSON for the message field to guide retries","Handle HTTP-200-with-fail-status as a distinct failure class","Avoid exotic characters in collection names"],"tags":["instagram-api","api-response","status-field"],"backgroundTag":"api-non-ok-status","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}