Mintplex-Labs/anything-llm · error
${res.statusText || "Error fetching api keys."}
Error message
${res.statusText || "Error fetching api keys."} What it means
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 }`.
Source
Thrown at frontend/src/models/admin.js:199
headers: baseHeaders(),
body: JSON.stringify(updates),
})
.then((res) => res.json())
.catch((e) => {
console.error(e);
return { success: false, error: e.message };
});
},
// API Keys
getApiKeys: async function () {
return fetch(`${API_BASE}/admin/api-keys`, {
method: "GET",
headers: baseHeaders(),
})
.then((res) => {
if (!res.ok) {
throw new Error(res.statusText || "Error fetching api keys.");
}
return res.json();
})
.catch((e) => {
console.error(e);
return { apiKeys: [], error: e.message };
});
},
generateApiKey: async function (data = {}) {
return fetch(`${API_BASE}/admin/generate-api-key`, {
method: "POST",
headers: baseHeaders(),
body: JSON.stringify(data),
})
.then((res) => {
if (!res.ok) {
throw new Error(res.statusText || "Error generating api key.");
}View on GitHub (pinned to 526360e320)
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.
Example fix
// before
if (!res.ok) throw new Error(res.statusText || 'Error fetching api keys.');
// after — include status + server message for actionable errors
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body?.error || `Error fetching api keys (HTTP ${res.status})`);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure auth is present before the call:
function assertAuthed() {
const token = getToken(); // whatever baseHeaders() relies on
if (!token) throw new Error('Not authenticated');
} Type guard
function isAuthFailure(e) { return /401|unauthor|Forbidden|403/i.test(e?.message || ''); } Try / catch
const { apiKeys, error } = await Admin.getApiKeys();
if (error) {
if (isAuthFailure({ message: error })) { await redirectToLogin(); return; }
showToast(error);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${res.statusText || "Error generating api key."}
- ${res.error || "Failed to save flow"}
- ${res.error || "Failed to get flow"}
- ${res.error || "Failed to delete flow"}
- ${res.error || "Failed to toggle flow"}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/66946fd8567a44d0.
Report an issue: GitHub.