{"record":{"id":"66946fd8567a44d0","repo":"Mintplex-Labs/anything-llm","slug":"res-statustext-error-fetching-api-keys","errorCode":null,"errorMessage":"${res.statusText || \"Error fetching api keys.\"}","messagePattern":"\\$\\{res\\.statusText \\|\\| \"Error fetching api keys\\.\"\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/models/admin.js","lineNumber":199,"sourceCode":"      headers: baseHeaders(),\n      body: JSON.stringify(updates),\n    })\n      .then((res) => res.json())\n      .catch((e) => {\n        console.error(e);\n        return { success: false, error: e.message };\n      });\n  },\n\n  // API Keys\n  getApiKeys: async function () {\n    return fetch(`${API_BASE}/admin/api-keys`, {\n      method: \"GET\",\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (!res.ok) {\n          throw new Error(res.statusText || \"Error fetching api keys.\");\n        }\n        return res.json();\n      })\n      .catch((e) => {\n        console.error(e);\n        return { apiKeys: [], error: e.message };\n      });\n  },\n  generateApiKey: async function (data = {}) {\n    return fetch(`${API_BASE}/admin/generate-api-key`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(data),\n    })\n      .then((res) => {\n        if (!res.ok) {\n          throw new Error(res.statusText || \"Error generating api key.\");\n        }","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/admin.js#L181-L217","documentation":"Thrown from the frontend `getApiKeys` model when the `GET /api/admin/api-keys` response is not ok (`res.ok === false`). It uses `res.statusText` as the message, falling back to 'Error fetching api keys.' Since `statusText` is often empty on modern HTTP/2 responses, the generic fallback frequently surfaces. The `.catch` swallows the throw and returns `{ apiKeys: [], error }`.","triggerScenarios":"401/403 (not authenticated or not an admin), 500 (backend error listing keys), network failure (the catch covers it), session expired while the admin panel is open, CORS/cookie not sent because `baseHeaders()` auth is missing.","commonSituations":"Admin leaves the tab open, session expires, then navigates to API Keys; backend API-key store errors; reverse proxy returns a non-2xx; cookie/header auth not attached in cross-origin setups.","solutions":["Confirm the user is logged in and has admin role; redirect to login on 401.","Inspect the network tab for the actual status code — the message may be generic but the status is specific.","Ensure `baseHeaders()` includes the auth token/cookie and the request is same-origin or CORS is configured.","Check backend `/admin/api-keys` logs for the 500 root cause.","Surface `res.status` to the UI instead of just statusText for clearer diagnostics."],"exampleFix":"// before\nif (!res.ok) throw new Error(res.statusText || 'Error fetching api keys.');\n\n// after — include status + server message for actionable errors\nif (!res.ok) {\n  const body = await res.json().catch(() => ({}));\n  throw new Error(body?.error || `Error fetching api keys (HTTP ${res.status})`);\n}","handlingStrategy":"try-catch","validationCode":"// Ensure auth is present before the call:\nfunction assertAuthed() {\n  const token = getToken(); // whatever baseHeaders() relies on\n  if (!token) throw new Error('Not authenticated');\n}","typeGuard":"function isAuthFailure(e) { return /401|unauthor|Forbidden|403/i.test(e?.message || ''); }","tryCatchPattern":"const { apiKeys, error } = await Admin.getApiKeys();\nif (error) {\n  if (isAuthFailure({ message: error })) { await redirectToLogin(); return; }\n  showToast(error);\n}","preventionTips":["Refresh the page/session before opening the admin panel.","Ensure baseHeaders() attaches the auth token/cookie on every request.","Surface res.status to the UI for clearer diagnostics."],"tags":["frontend","api-keys","admin","network","fetch"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}