{"record":{"id":"fe047e27408ee691","repo":"jackwener/OpenCLI","slug":"instagram-returned-non-ok-status-json-stringify-fe047e","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-delete.js","lineNumber":82,"sourceCode":"    id = String(matches[0].collection_id);\n    resolvedName = String(matches[0].collection_name || raw);\n  }\n\n  const fd = new FormData();\n  fd.append('module_name', 'collection_settings');\n  const res = await fetch('https://www.instagram.com/api/v1/collections/' + encodeURIComponent(id) + '/delete/', {\n    method: 'POST',\n    credentials: 'include',\n    headers: { ...headers, 'X-CSRFToken': csrf },\n    body: fd,\n  });\n  if (!res.ok) {\n    const body = await res.text().catch(() => '');\n    throw new Error('Failed to delete collection: HTTP ' + res.status + (body ? ' - ' + body.slice(0, 200) : ''));\n  }\n  const d = await res.json().catch(() => ({}));\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: 'Deleted',\n    collectionId: id,\n    collectionName: resolvedName,\n  }];\n})()\n` },\n    ],\n});\n","sourceCodeStart":64,"sourceCodeEnd":93,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-delete.js#L64-L93","documentation":"Thrown after a successful HTTP DELETE of an Instagram collection when the JSON body contains a 'status' field that is not 'ok'. Instagram sometimes returns HTTP 200 with an in-body error status, so the CLI inspects the parsed payload and surfaces the first 300 chars of it. It means the API acknowledged the request but did not confirm success.","triggerScenarios":"DELETE /api/v1/collections/{id}/delete/ returns 200 with body {\"status\":\"fail\"} or similar; session/CSRF issues, rate limiting, or Instagram soft-blocking the collection delete while returning HTTP 200.","commonSituations":"Stale or partially-invalid session cookies causing IG to reject the mutation in-body; deleting a collection that was already removed via the app; Instagram A/B responses where the operation was not applied.","solutions":["Log the full response body (the error already embeds 300 chars) and check d.status / d.message for the real reason","Refresh Instagram session cookies and retry the delete","Verify the collection still exists; if already deleted, treat this as idempotent success","Retry after a backoff if the status indicates rate limiting or transient failure"],"exampleFix":"// before\nif (d?.status && d.status !== 'ok') {\n  throw new Error('Instagram returned non-ok status: ' + JSON.stringify(d).slice(0, 300));\n}\n// after\nif (d?.status && d.status !== 'ok') {\n  if (d.status === 'fail' && /already deleted|not found/i.test(d.message || '')) {\n    return [{ status: 'Deleted', collectionId: id, collectionName: resolvedName }];\n  }\n  throw new Error('Instagram returned non-ok status: ' + JSON.stringify(d).slice(0, 300));\n}","handlingStrategy":"validation","validationCode":"const d = await res.json().catch(() => ({}));\nif (d?.status && d.status !== 'ok') {\n  console.error('Delete not confirmed:', JSON.stringify(d));\n  // treat as failure or check whether collection already gone before rethrowing\n}","typeGuard":"function isOkStatus(d) {\n  return !!d && typeof d === 'object' && (d.status === undefined || d.status === 'ok');\n}","tryCatchPattern":"try {\n  await deleteCollection(id, name);\n} catch (e) {\n  if (/non-ok status/.test(e.message)) {\n    // inspect embedded JSON body, refresh cookies, retry once\n  } else throw e;\n}","preventionTips":["Keep Instagram session cookies fresh","Check response body status fields even when HTTP 200","Treat already-deleted collections as success for idempotency","Rate-limit destructive calls to avoid soft blocks"],"tags":["instagram","http-status","api-response","json"],"backgroundTag":"instagram-non-ok-status","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}