{"record":{"id":"7aa0ab59525fbdcd","repo":"jackwener/OpenCLI","slug":"failed-to-delete-collection-http-res-status-b","errorCode":null,"errorMessage":"Failed to delete collection: HTTP ${res.status}${body ? ' - ' + body.slice(0, 200) : ''}","messagePattern":"Failed to delete collection: HTTP (.+?)(.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/collection-delete.js","lineNumber":78,"sourceCode":"    if (matches.length > 1) {\n      const ids = matches.map((c) => c.collection_id).join(', ');\n      throw new Error('Multiple collections share the name \"' + raw + '\" (ids: ' + ids + '). Pass the numeric collection_id explicitly to disambiguate.');\n    }\n    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":60,"sourceCodeEnd":93,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-delete.js#L60-L93","documentation":"Thrown when the final POST that deletes the resolved collection returns non-2xx. The status code and first 200 chars of Instagram's response body are embedded to expose the reason (auth, rate limit, already deleted). It is the transport-level failure guard for the delete call.","triggerScenarios":"Deleting with an expired CSRF token/session (403), rate limiting (429), the collection having been deleted concurrently (404), or Instagram API changes to the delete endpoint.","commonSituations":"Long-running scripts whose session expires mid-deletion; batch delete loops hitting rate limits; races where another client deleted the collection first.","solutions":["Read the body slice for Instagram's specific error message","Re-authenticate to refresh csrftoken/session if 401/403","Add backoff and retry for 429 rate-limit responses","Re-resolve the collection (it may no longer exist) before retrying"],"exampleFix":"// before\nthrow new Error('Failed to delete collection: HTTP ' + res.status + ...);\n// after\nif (res.status === 429) { await sleep(60000); return deleteCollection(target); }\nthrow new Error('Failed to delete collection: HTTP ' + res.status + ...);","handlingStrategy":"retry","validationCode":"// Pre-resolve and confirm the collection still exists before deleting\nconst list = await listCollections();\nif (!list.some((c) => String(c.collection_id) === id)) throw new Error('Collection already gone: ' + id);","typeGuard":"function isRetryableHttpStatus(msg: string): boolean {\n  const m = msg.match(/HTTP (\\d+)/);\n  return !!m && ['408', '429', '500', '502', '503', '504'].includes(m[1]);\n}","tryCatchPattern":"try {\n  await deleteCollection(id);\n} catch (e) {\n  const m = String(e.message).match(/HTTP (\\d+)/);\n  if (m && m[1] === '429') { await sleep(60000); return deleteCollection(id); }\n  if (m && m[1] === '403') { await relogin(); return deleteCollection(id); }\n  throw e;\n}","preventionTips":["Space out delete operations to avoid 429 rate limits","Refresh sessions before long delete batches","Treat 404 as 'already deleted' and continue rather than failing","Log response bodies to detect Instagram API behavior changes early"],"tags":["http","network","instagram-api","rate-limit"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}