{"record":{"id":"57dbd9cfa70cffd2","repo":"odysseus-dev/odysseus","slug":"http-res-status-57dbd9","errorCode":null,"errorMessage":"HTTP ${res.status}","messagePattern":"HTTP \\$\\{res\\.status\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"static/js/documentLibrary.js","lineNumber":1196,"sourceCode":"    if (archiveBtn) {\n      archiveBtn.disabled = _librarySelectedIds.size === 0;\n      archiveBtn.textContent = _libraryArchivedView ? 'Restore' : 'Archive';\n    }\n  }\n\n  async function libraryDeleteSingle(docId, card) {\n    if (uiModule && uiModule.styledConfirm) {\n      const ok = await uiModule.styledConfirm('Delete this document?', { confirmText: 'Delete', danger: true });\n      if (!ok) return;\n    } else if (!confirm('Delete this document?')) {\n      return;\n    }\n    try {\n      const res = await fetch(`${API_BASE}/api/document/${docId}`, { method: 'DELETE', credentials: 'same-origin' });\n      if (!res.ok) {\n        let detail = `HTTP ${res.status}`;\n        try { const j = await res.json(); if (j?.detail) detail = j.detail; } catch {}\n        throw new Error(detail);\n      }\n      if (card) {\n        card.classList.add('doclib-card-deleting');\n        card.addEventListener('transitionend', () => card.remove(), { once: true });\n        setTimeout(() => { if (card.parentElement) card.remove(); }, 400);\n      }\n      libraryRemoveDocumentFromState(docId);\n      if (uiModule) uiModule.showToast('Document deleted');\n    } catch (e) {\n      if (uiModule) uiModule.showError(`Failed to delete document: ${e.message || e}`);\n    }\n  }\n\n  async function libraryBulkDelete() {\n    if (_librarySelectedIds.size === 0) return;\n    const count = _librarySelectedIds.size;\n    if (uiModule && uiModule.styledConfirm) {\n      const ok = await uiModule.styledConfirm(","sourceCodeStart":1178,"sourceCodeEnd":1214,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/static/js/documentLibrary.js#L1178-L1214","documentation":"Thrown by libraryDeleteSingle in documentLibrary.js when DELETE /api/document/<docId> returns non-2xx. Unlike document.js's delete, this site parses the response body and prefers j.detail, falling back to `HTTP <status>`, and reports via 'Failed to delete document: <msg>'. The card is only removed after the transition, so failure leaves the card intact.","triggerScenarios":"Deleting from the Library grid when the doc was already purged (404 with a FastAPI-style detail body), auth expired (401), or server 500. Unlike error 53 this call does send credentials: 'same-origin'.","commonSituations":"Deleting in one tab while the Library in another tab is stale; server-side cascade/constraint errors; session cookie expired between load and delete.","solutions":["Read the toast — it includes the backend detail, which usually names the cause.","If 404, refresh the Library; the entry is stale and will disappear on reload (or treat 404 as success and remove the card locally).","Re-authenticate if 401.","Check server logs for 5xx during DELETE."],"exampleFix":"// before\nif (!res.ok) {\n  let detail = `HTTP ${res.status}`;\n  try { const j = await res.json(); if (j?.detail) detail = j.detail; } catch {}\n  throw new Error(detail);\n}\n\n// after — treat 404 as already-deleted so the stale card still clears\nif (!res.ok && res.status !== 404) {\n  let detail = `HTTP ${res.status}`;\n  try { const j = await res.json(); if (j?.detail || j?.error) detail = j.detail || j.error; } catch {}\n  throw new Error(detail);\n}","handlingStrategy":"try-catch","validationCode":"if (!docId || !/^[\\w-]+$/.test(String(docId))) return;","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(`${API_BASE}/api/document/${docId}`, { method: 'DELETE', credentials: 'same-origin' });\n  if (!res.ok && res.status !== 404) {\n    let detail = `HTTP ${res.status}`;\n    try { const j = await res.json(); if (j?.detail) detail = j.detail; } catch {}\n    throw new Error(detail);\n  }\n  removeCard(card); // 404 means already deleted — still clear the stale card\n} catch (a) {\n  if (uiModule) uiModule.showError(`Failed to delete document: ${a.message || a}`);\n}","preventionTips":["Handle 404 as eventual success for deletes and remove stale cards instead of leaving them forever.","Refresh the Library after external deletions to avoid acting on stale ids.","Keep the detail-parsing pattern this site already uses; replicate it at the document.js delete call site."],"tags":["http","delete","library","api-error"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}