{"record":{"id":"c02ca8664f62afe8","repo":"srbhr/Resume-Matcher","slug":"data-detail-failed-to-apply-enhancements-sta","errorCode":null,"errorMessage":"${data.detail || Failed to apply enhancements (status ${res.status}).}","messagePattern":"\\$\\{data\\.detail \\|\\| Failed to apply enhancements \\(status \\$\\{res\\.status\\}\\)\\.\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/frontend/lib/api/enrichment.ts","lineNumber":99,"sourceCode":"  }\n\n  return res.json();\n}\n\n/**\n * Apply enhancements to the master resume.\n */\nexport async function applyEnhancements(\n  resumeId: string,\n  enhancements: EnhancedDescription[]\n): Promise<{ message: string; updated_items: number }> {\n  const res = await apiPost(`/enrichment/apply/${resumeId}`, {\n    enhancements,\n  });\n\n  if (!res.ok) {\n    const data = await res.json().catch(() => ({}));\n    throw new Error(data.detail || `Failed to apply enhancements (status ${res.status}).`);\n  }\n\n  return res.json();\n}\n\n// ============================================\n// AI Regenerate Feature Types\n// ============================================\n\nexport interface RegenerateItemInput {\n  item_id: string;\n  item_type: 'experience' | 'project' | 'skills';\n  title: string;\n  subtitle?: string;\n  current_content: string[];\n}\n\nexport interface RegenerateRequest {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/frontend/lib/api/enrichment.ts#L81-L117","documentation":"applyEnhancements in apps/frontend/lib/api/enrichment.ts throws this Error when the POST to `/enrichment/apply/{resumeId}` returns a non-OK response. It surfaces the backend `detail` message when present, otherwise a generic message with the HTTP status. It means the server refused or failed to persist the chosen enhancements onto the resume.","triggerScenarios":"apiPost(`/enrichment/apply/${resumeId}`, { enhancements }) yields 401 (no valid session), 404 (resumeId not found), 422 (enhancements array empty or items missing required fields like id/content), or 5xx (database write failure / backend crash while saving).","commonSituations":"User clicks Apply after the resume was deleted elsewhere (404); stale enhancement objects from an older API version fail validation (422); the database is unavailable or the update transaction fails (500); auth cookie expired mid-flow (401).","solutions":["Check res.status first: 401 -> re-authenticate; 404 -> verify the resume still exists; 422 -> validate the enhancements payload; 5xx -> inspect backend logs.","Ensure the enhancements being applied came from the current generation response and were not mutated/emptied before submit.","Re-fetch the resume after a 404 and inform the user the resume no longer exists.","Add idempotency/retry only for network-level failures and 502/503/504, not for 4xx.","Confirm the API base URL and route version match the backend deployment."],"exampleFix":"// before\nif (!res.ok) {\n  const data = await res.json().catch(() => ({}));\n  throw new Error(data.detail || `Failed to apply enhancements (status ${res.status}).`);\n}\n// after\nif (!res.ok) {\n  if (enhancements.length === 0) throw new Error('No enhancements selected to apply.');\n  const data = await res.json().catch(() => ({}));\n  throw new Error(data.detail || `Failed to apply enhancements (status ${res.status}).`);\n}","handlingStrategy":"try-catch","validationCode":"if (!resumeId?.trim() || !Array.isArray(enhancements) || enhancements.length === 0) {\n  throw new Error('Cannot apply: missing resumeId or no enhancements selected.');\n}","typeGuard":"function isApplicableEnhancements(v: unknown): v is EnhancementPreview[] {\n  return Array.isArray(v) && v.length > 0 && v.every(x =>\n    typeof x === 'object' && x !== null && 'item_id' in x);\n}","tryCatchPattern":"try {\n  await applyEnhancements(resumeId, selectedEnhancements);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : '';\n  if (msg.includes('status 404')) showError('This resume no longer exists.');\n  else if (msg.includes('status 401')) redirectToLogin();\n  else showError('Applying changes failed. Your selections are preserved — please retry.');\n}","preventionTips":["Only apply enhancements that came from the most recent generation response; never persist stale previews across resumes.","Keep selected enhancements in component state so a failed apply does not lose user selections.","Check resume existence before the enrichment flow when the resume may have been deleted elsewhere."],"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"}