{"record":{"id":"0cd5aa3d8c7216ec","repo":"srbhr/Resume-Matcher","slug":"text-resume-wizard-finalize-failed-with-statu","errorCode":null,"errorMessage":"${text || Resume wizard finalize failed with status ${response.status}}","messagePattern":"\\$\\{text \\|\\| Resume wizard finalize failed with status \\$\\{response\\.status\\}\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/frontend/lib/api/resume-wizard.ts","lineNumber":121,"sourceCode":"\nexport async function postResumeWizardTurn(\n  payload: ResumeWizardTurnRequest\n): Promise<ResumeWizardTurnResponse> {\n  const response = await apiPost('/resume-wizard/turn', payload);\n  if (!response.ok) {\n    const text = await response.text().catch(() => '');\n    throw new Error(text || `Resume wizard turn failed with status ${response.status}`);\n  }\n  return response.json();\n}\n\nexport async function finalizeResumeWizard(\n  state: ResumeWizardState\n): Promise<ResumeWizardFinalizeResponse> {\n  const response = await apiPost('/resume-wizard/finalize', { state });\n  if (!response.ok) {\n    const text = await response.text().catch(() => '');\n    throw new Error(text || `Resume wizard finalize failed with status ${response.status}`);\n  }\n  return response.json();\n}\n","sourceCodeStart":103,"sourceCodeEnd":125,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/frontend/lib/api/resume-wizard.ts#L103-L125","documentation":"finalizeResumeWizard in apps/frontend/lib/api/resume-wizard.ts throws this Error when the POST to `/resume-wizard/finalize` returns a non-OK response. It reads the raw response text as the error message (falling back to a status-embedded string), meaning the backend refused to finalize the wizard state into a finished resume.","triggerScenarios":"apiPost('/resume-wizard/finalize', { state }) yields response.ok === false: 401 unauthenticated, 404 resume/state id not found, 422 state object incomplete or from an incompatible wizard version, 429/500/504 from the AI finalization step.","commonSituations":"User reaches the final step after a long session and the cookie expired (401); the state was persisted before a schema migration and finalize now rejects it (422); final document generation exceeds a gateway timeout (504); backend storage failure while creating the resume (500).","solutions":["Inspect response.status and the raw text; treat HTML-looking bodies as gateway errors and check the proxy.","For 422, validate the ResumeWizardState (all required sections completed) before finalizing.","For 401, re-authenticate, restore the state, and retry finalize.","For 5xx/429, retry with backoff and verify backend AI/timeout configuration.","Persist wizard state locally so a failed finalize can be retried without losing progress."],"exampleFix":"// before\nconst response = await apiPost('/resume-wizard/finalize', { state });\nif (!response.ok) {\n  const text = await response.text().catch(() => '');\n  throw new Error(text || `Resume wizard finalize failed with status ${response.status}`);\n}\n// after\nconst response = await apiPost('/resume-wizard/finalize', { state });\nif (!response.ok) {\n  if (response.status === 401) throw new Error('Session expired. Please sign in and finalize again.');\n  const text = await response.text().catch(() => '');\n  throw new Error(text || `Resume wizard finalize failed with status ${response.status}`);\n}","handlingStrategy":"validation","validationCode":"function canFinalize(state: ResumeWizardState): boolean {\n  return Boolean(state && Array.isArray(state.messages) && state.messages.length > 0);\n}\nif (!canFinalize(state)) throw new Error('Wizard state is incomplete — finalize requires a completed conversation.');","typeGuard":"function isFinalizableState(s: unknown): s is ResumeWizardState {\n  return typeof s === 'object' && s !== null && 'messages' in s &&\n    Array.isArray((s as ResumeWizardState).messages);\n}","tryCatchPattern":"try {\n  const result = await finalizeResumeWizard(state);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : '';\n  if (msg.includes('status 401')) { await reauth(); return finalizeResumeWizard(state); }\n  showError('Finalizing your resume failed. Your progress is saved — please retry.');\n}","preventionTips":["Validate the wizard state is complete before finalizing; disable the Finish button otherwise.","Persist state before finalize so a 401 re-login can resume without data loss.","Increase gateway timeout or stream the finalization if 504s occur on large resumes."],"tags":["http-error","fetch","ai","api-client"],"backgroundTag":"http-non-ok-response","analyzedSha":"116f9cc3b00e1ac91734a6c2679bf41ea64a0edc","analyzedAt":"2026-08-28T22:51:40.999Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}