{"record":{"id":"5dfd91f820ad5fcd","repo":"decolua/9router","slug":"failed-to-export-database","errorCode":null,"errorMessage":"Failed to export database","messagePattern":"Failed to export database","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/app/(dashboard)/dashboard/profile/page.js","lineNumber":666,"sourceCode":"      const res = await fetch(\"/api/settings\");\n      if (!res.ok) return;\n      const data = await res.json();\n      setSettings(data);\n    } catch (err) {\n      console.error(\"Failed to reload settings:\", err);\n    }\n  };\n\n  const handleExportDatabase = async (password) => {\n    setDbLoading(true);\n    setDbStatus({ type: \"\", message: \"\" });\n    try {\n      const res = await fetch(\"/api/settings/database\", {\n        headers: { \"x-9r-password\": password },\n      });\n      if (!res.ok) {\n        const data = await res.json().catch(() => ({}));\n        throw new Error(data.error || \"Failed to export database\");\n      }\n\n      const payload = await res.json();\n      const content = JSON.stringify(payload, null, 2);\n      const blob = new Blob([content], { type: \"application/json\" });\n      const url = URL.createObjectURL(blob);\n      const anchor = document.createElement(\"a\");\n      const stamp = new Date().toISOString().replace(/[.:]/g, \"-\");\n      anchor.href = url;\n      anchor.download = `9router-backup-${stamp}.json`;\n      document.body.appendChild(anchor);\n      anchor.click();\n      document.body.removeChild(anchor);\n      URL.revokeObjectURL(url);\n\n      setDbStatus({ type: \"success\", message: \"Database backup downloaded\" });\n    } catch (err) {\n      setDbStatus({ type: \"error\", message: err.message || \"Failed to export database\" });","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/app/(dashboard)/dashboard/profile/page.js#L648-L684","documentation":"ProfilePage's database export handler throws this when GET /api/settings/database (sent with an x-9r-password header) responds non-2xx without a specific error field. Export requires a correct admin password; the generic message commonly masks a wrong-password 401 or a server-side dump failure.","triggerScenarios":"GET /api/settings/database with header x-9r-password returns non-2xx: password incorrect/missing (401/403), server fails to serialize the SQLite data (500), or res.json() succeeds but data.error is absent.","commonSituations":"User typed the dashboard admin password wrong in the export prompt; database is large and dump times out; running an older server version whose endpoint requires different auth; empty password field submitted.","solutions":["Check the HTTP status/network response of the export request for the real error","Re-enter the admin password correctly (most common cause is a wrong x-9r-password)","Retry after confirming the server is running and the database file is readable","Check server logs for a serialization/dump failure if the password is confirmed correct"],"exampleFix":"// before\nthrow new Error(data.error || \"Failed to export database\");\n// after\nthrow new Error(data.error || `Failed to export database (HTTP ${res.status})`);","handlingStrategy":"try-catch","validationCode":"// before calling\nif (!password) throw new Error(\"Admin password required to export\");","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(\"/api/settings/database\", { headers: { \"x-9r-password\": password } });\n  if (!res.ok) {\n    const data = await res.json().catch(() => ({}));\n    throw new Error(data.error || `Failed to export database (HTTP ${res.status})`);\n  }\n} catch (err) {\n  setDbStatus({ type: \"error\", message: err.message });\n}","preventionTips":["Re-enter the admin password carefully on 401/403","Handle 401 distinctly to prompt re-authentication instead of a generic failure","For large DBs, expect longer export times and retry on timeout","Verify the server version supports the export endpoint"],"tags":["http","database","export","auth"],"backgroundTag":"http-request-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}