{"record":{"id":"36279b6f87afb66d","repo":"srbhr/Resume-Matcher","slug":"data-detail-failed-to-reset-database-status","errorCode":null,"errorMessage":"${data.detail || Failed to reset database (status ${res.status}).}","messagePattern":"\\$\\{data\\.detail \\|\\| Failed to reset database \\(status \\$\\{res\\.status\\}\\)\\.\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/frontend/lib/api/config.ts","lineNumber":543,"sourceCode":"\n  if (!res.ok) {\n    const data = await res.json().catch(() => ({}));\n    throw new Error(data.detail || `Failed to clear API keys (status ${res.status}).`);\n  }\n}\n\n// Reset database\nexport async function resetDatabase(): Promise<void> {\n  const res = await apiFetch('/config/reset', {\n    method: 'POST',\n    credentials: 'include',\n    headers: { 'Content-Type': 'application/json' },\n    body: JSON.stringify({ confirm: 'RESET_ALL_DATA' }),\n  });\n\n  if (!res.ok) {\n    const data = await res.json().catch(() => ({}));\n    throw new Error(data.detail || `Failed to reset database (status ${res.status}).`);\n  }\n}\n","sourceCodeStart":525,"sourceCodeEnd":546,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/frontend/lib/api/config.ts#L525-L546","documentation":"resetDatabase POSTs to /config/reset with body {confirm: 'RESET_ALL_DATA'} and throws this when the response is not ok, preferring the backend `detail`. It wipes all resumes/jobs/config data; the backend requires the exact confirm token, and any non-2xx (refusal, auth, crash) is reported through this throw to handleResetDatabase.","triggerScenarios":"Non-2xx on POST /config/reset: 400/403 when the confirm body is absent or doesn't equal 'RESET_ALL_DATA', 401 (expired session), 404 (route/proxy misroute), 500/503 when the backend fails mid-reset (DB locked, file permissions, disk full).","commonSituations":"Hand-rolled requests omitting the confirm payload; session expiring before the destructive click; SQLite file locked by another process; Docker volume mounted read-only so the DB can't be cleared.","solutions":["Ensure the request body is exactly {confirm: 'RESET_ALL_DATA'} with Content-Type: application/json.","401/403 → re-authenticate and retry; 404 → check BACKEND_ORIGIN and next.config.ts rewrites.","For 5xx, inspect backend logs — a partial reset may need the DB/volume permission or lock issue fixed before retrying.","Gate the action behind a typed confirmation dialog and catch the error to report reset failure clearly instead of leaving stale UI."],"exampleFix":"// before\ntry {\n  await resetDatabase();\n} finally {\n  window.location.reload();\n}\n\n// after\ntry {\n  await resetDatabase();\n  window.location.reload();\n} catch (e) {\n  setResetError(e instanceof Error ? e.message : 'Database reset failed — data was NOT cleared');\n}","handlingStrategy":"validation","validationCode":"const body = JSON.stringify({ confirm: 'RESET_ALL_DATA' });\nif (!body.includes('RESET_ALL_DATA')) {\n  throw new Error('Reset requires the RESET_ALL_DATA confirm token');\n}","typeGuard":"function isResetBody(x: unknown): x is { confirm: 'RESET_ALL_DATA' } {\n  return typeof x === 'object' && x !== null && (x as any).confirm === 'RESET_ALL_DATA';\n}","tryCatchPattern":"const phrase = await confirmDialog({\n  title: 'Reset database? All resumes and jobs will be deleted.',\n  requireTyped: 'RESET',\n});\nif (!phrase) return;\ntry {\n  await resetDatabase();\n  showToast('Database reset');\n} catch (e) {\n  setResetError(e instanceof Error ? e.message : 'Reset failed — data intact');\n}","preventionTips":["Always send Content-Type: application/json with the confirm body","Use a typed-confirmation dialog for irreversible resets","Never reload the page in a finally block — wait for success","Check DB file locks and volume permissions if the reset 500s repeatedly"],"tags":["network","http","database","destructive-operation"],"backgroundTag":"missing-confirm-parameter","analyzedSha":"116f9cc3b00e1ac91734a6c2679bf41ea64a0edc","analyzedAt":"2026-08-28T22:51:40.999Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}