{"record":{"id":"6c3060cba1bfa139","repo":"srbhr/Resume-Matcher","slug":"data-detail-failed-to-apply-changes-status","errorCode":null,"errorMessage":"${data.detail || Failed to apply changes (status ${res.status}).}","messagePattern":"\\$\\{data\\.detail \\|\\| Failed to apply changes \\(status \\$\\{res\\.status\\}\\)\\.\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/frontend/lib/api/enrichment.ts","lineNumber":173,"sourceCode":"    const data = await res.json().catch(() => ({}));\n    throw new Error(data.detail || `Failed to regenerate content (status ${res.status}).`);\n  }\n\n  return res.json();\n}\n\n/**\n * Apply regenerated items to the master resume.\n */\nexport async function applyRegeneratedItems(\n  resumeId: string,\n  regeneratedItems: RegeneratedItem[]\n): Promise<{ message: string; updated_items: number }> {\n  const res = await apiPost(`/enrichment/apply-regenerated/${resumeId}`, regeneratedItems);\n\n  if (!res.ok) {\n    const data = await res.json().catch(() => ({}));\n    throw new Error(data.detail || `Failed to apply changes (status ${res.status}).`);\n  }\n\n  return res.json();\n}\n","sourceCodeStart":155,"sourceCodeEnd":178,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/frontend/lib/api/enrichment.ts#L155-L178","documentation":"applyRegeneratedItems in apps/frontend/lib/api/enrichment.ts throws this Error when the POST to `/enrichment/apply-regenerated/{resumeId}` returns a non-OK response. It surfaces the backend `detail` message or a generic status-embedded message. It means the server could not persist the regenerated items back onto the resume.","triggerScenarios":"apiPost(`/enrichment/apply-regenerated/${resumeId}`, regeneratedItems) resolves non-OK: 401 unauthenticated, 404 resumeId missing, 422 regeneratedItems is an empty array or items lack required fields (id, content) per the backend schema, or 5xx on the database write.","commonSituations":"User accepts changes after regenerating, but the resume was deleted in another tab (404); the regenerated items array is empty because all regeneration failed upstream (422); auth cookie expired between generate and apply (401); DB constraint/lock failure on the backend (500).","solutions":["Check res.status to distinguish auth (401), missing resume (404), payload (422), and server (5xx) causes.","Guard against applying an empty regeneratedItems array client-side before calling.","On 404, refresh the resume list and tell the user the resume no longer exists.","On 401, prompt re-login and retry the apply once.","Inspect backend logs for persistence errors on 5xx and verify DB connectivity."],"exampleFix":"// before\nconst res = await apiPost(`/enrichment/apply-regenerated/${resumeId}`, regeneratedItems);\nif (!res.ok) {\n  const data = await res.json().catch(() => ({}));\n  throw new Error(data.detail || `Failed to apply changes (status ${res.status}).`);\n}\n// after\nif (regeneratedItems.length === 0) {\n  throw new Error('There are no regenerated changes to apply.');\n}\nconst res = await apiPost(`/enrichment/apply-regenerated/${resumeId}`, regeneratedItems);\nif (!res.ok) {\n  const data = await res.json().catch(() => ({}));\n  throw new Error(data.detail || `Failed to apply changes (status ${res.status}).`);\n}","handlingStrategy":"validation","validationCode":"if (!resumeId?.trim()) throw new Error('resumeId is required to apply regenerated items.');\nif (!Array.isArray(regeneratedItems) || regeneratedItems.length === 0) {\n  throw new Error('No regenerated items to apply.');\n}","typeGuard":"function isRegeneratedItemList(v: unknown): v is RegeneratedItem[] {\n  return Array.isArray(v) && v.length > 0 && v.every(x =>\n    typeof x === 'object' && x !== null && 'id' in x && 'content' in x);\n}","tryCatchPattern":"try {\n  const { updated_items } = await applyRegeneratedItems(resumeId, regeneratedItems);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : '';\n  if (msg.includes('status 404')) showError('Resume not found — it may have been deleted.');\n  else if (msg.includes('status 401')) redirectToLogin();\n  else showError('Could not save regenerated changes. Please retry.');\n}","preventionTips":["Guard against empty regeneratedItems arrays before calling apply.","Confirm resume existence before long enrichment flows if deletions elsewhere are possible.","Show a clean message instead of leaking raw backend detail strings to end users."],"tags":["http-error","fetch","api-client","persistence"],"backgroundTag":"http-non-ok-response","analyzedSha":"116f9cc3b00e1ac91734a6c2679bf41ea64a0edc","analyzedAt":"2026-08-28T22:51:40.999Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}