{"record":{"id":"d1f29ee8f77bdc58","repo":"pbakaus/impeccable","slug":"http-res-status","errorCode":null,"errorMessage":"HTTP ${res.status}","messagePattern":"HTTP \\$\\{res\\.status\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skill/scripts/live-browser.js","lineNumber":4170,"sourceCode":"    } finally {\n      if (waitForSseCompletion) return;\n      const remainingCount = parseInt(pendingPillEl?.dataset.count || '0', 10) || 0;\n      if (remainingCount > 0) setPendingApplyLoading(false);\n      else hidePendingApplyDock();\n    }\n  }\n\n  async function onPendingTrashClick() {\n    const count = parseInt(pendingPillEl?.dataset.count || '0', 10);\n    if (count <= 0 || pendingApplyInFlight) return;\n    const ok = confirm('Discard ' + count + ' copy edit' + (count === 1 ? '' : 's') + ' on this page?');\n    if (!ok) return;\n    try {\n      const res = await fetch(\n        'http://localhost:' + PORT + '/manual-edit-discard?token=' + encodeURIComponent(TOKEN) + '&pageUrl=' + encodeURIComponent(location.pathname),\n        { method: 'POST' },\n      );\n      if (!res.ok) throw new Error('HTTP ' + res.status);\n      const result = await res.json().catch(() => ({}));\n      const restoreFailures = restoreDiscardedManualEdits(result.entries || []);\n      updatePendingCounter(0);\n      if (restoreFailures > 0) {\n        showToast('Discarded ' + count + ' copy edit' + (count === 1 ? '' : 's') + ' - refresh to reset ' + restoreFailures, 4000);\n      } else {\n        showToast('Discarded ' + count + ' copy edit' + (count === 1 ? '' : 's'), 2500);\n      }\n    } catch (err) {\n      console.error('[impeccable] discard failed:', err);\n      showToast('Discard failed - see console', 4000);\n    }\n  }\n\n  function showManualApplyDecision(msg) {\n    const count = parseInt(pendingPillEl?.dataset.count || '0', 10) || numberOrNull(msg?.remainingCount) || 0;\n    pendingApplyInFlight = false;\n    storeManualApplyState(count, {","sourceCodeStart":4152,"sourceCodeEnd":4188,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/skill/scripts/live-browser.js#L4152-L4188","documentation":"Discarding manual edits POSTs to /manual-edit-discard; on a non-OK response the code throws Error('HTTP ' + res.status). Unlike the commit paths, this one does not parse the response body for a server error message, so you only get the status code.","triggerScenarios":"Clicking discard (trash) on pending copy edits while the dev server returns 4xx/5xx — e.g. stale token or unknown pageUrl.","commonSituations":"Dev server restarted (token mismatch); the pending-edit list changed server-side; transient server error during teardown.","solutions":["Note the status: 401/403 implies token mismatch — refresh the page to re-handshake","Check the dev-server logs for the /manual-edit-discard request failure","Retry the discard after refreshing; edits remain applied so nothing is lost","Re-run the live session if the server state has diverged"],"exampleFix":"// before\nif (!res.ok) throw new Error('HTTP ' + res.status);\n// after\nif (!res.ok) {\n  const errBody = await res.json().catch(() => ({}));\n  throw new Error(errBody.error || ('HTTP ' + res.status));\n}","handlingStrategy":"try-catch","validationCode":"async function discardIsSafe(port, token, pageUrl) {\n  const res = await fetch('http://localhost:' + port + '/state?token=' + token);\n  return res.ok; // server session alive before discarding\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(discardUrl, { method: 'POST' });\n  if (!res.ok) throw new Error('HTTP ' + res.status);\n} catch (e) {\n  showToast('Discard failed: ' + e.message + ' - refresh to re-sync', 4000);\n}","preventionTips":["Re-handshake (page refresh) whenever the dev server restarted","Check the pending counter is non-zero before discarding","Retry once on transient 5xx before showing a failure toast"],"tags":["http","fetch","dev-server"],"backgroundTag":"http-error-response","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}