Mintplex-Labs/anything-llm · error
${res.statusText || "Error generating api key."}
Error message
${res.statusText || "Error generating api key."} What it means
Thrown from `generateApiKey` when `POST /api/admin/generate-api-key` returns non-ok. Same shape as error 49: message is `res.statusText || 'Error generating api key.'`, caught and returned as `{ apiKey: null, error }`. Generation is a write, so 4xx validation errors are more likely here than on the GET.
Source
Thrown at frontend/src/models/admin.js:216
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.");
}
return res.json();
})
.catch((e) => {
console.error(e);
return { apiKey: null, error: e.message };
});
},
deleteApiKey: async function (apiKeyId = "") {
return fetch(`${API_BASE}/admin/delete-api-key/${apiKeyId}`, {
method: "DELETE",
headers: baseHeaders(),
})
.then((res) => res.ok)
.catch((e) => {
console.error(e);
return false;
});View on GitHub (pinned to 526360e320)
Solutions
- Validate the form payload client-side before posting.
- On 401, re-authenticate; on 403, confirm admin role.
- Check backend logs for the 400/500 detail — the generic message hides it.
- Improve the throw to read the JSON error body (the current code discards server-side error text).
Example fix
// before
if (!res.ok) throw new Error(res.statusText || 'Error generating api key.');
// after
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body?.error || `Error generating api key (HTTP ${res.status})`);
} Defensive patterns
Strategy: validation
Validate before calling
function validateApiKeyPayload(data) {
if (!data || typeof data !== 'object') throw new Error('API key payload is required');
return data;
} Type guard
function isAuthFailure(e) { return /401|unauthor|Forbidden|403/i.test(e?.message || ''); } Try / catch
const { apiKey, error } = await Admin.generateApiKey(payload);
if (error) {
if (isAuthFailure({ message: error })) { await redirectToLogin(); return; }
showToast(error);
} Prevention
- Validate the generate form client-side before posting.
- Re-auth on 401; check backend logs for 400/500 detail.
- Patch the model to read the JSON error body for the real message.
When it happens
Trigger: Request body missing required fields (e.g. created_by, permissions); 401/403 non-admin; 409/400 if a key with the same name exists; backend persistence failure (DB write error) returns 500; rate limiting.
Common situations: Form submitted with empty fields; session expired between opening the modal and clicking generate; DB locked or migration pending on the backend.
Related errors
- ${res.statusText || "Error fetching api keys."}
- ${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/7af5383197c9db11.
Report an issue: GitHub.