Mintplex-Labs/anything-llm · error · Error
res.statusText || "Error setting suggested messages."
Error message
res.statusText || "Error setting suggested messages."
What it means
Thrown by setSuggestedMessages in the AnythingLLM frontend when POST /api/workspace/:slug/suggested-messages responds non-2xx; the message is res.statusText or the fixed fallback. Separately, the success path `return { success: true, ...res.json() }` spreads a Promise (res.json() is never awaited), so the returned object's extra keys are garbage — a latent bug independent of this throw.
Source
Thrown at frontend/src/models/workspace.js:338
.then((res) => {
if (!res.ok) throw new Error("Could not fetch suggested messages.");
return res.json();
})
.then((res) => res.suggestedMessages)
.catch((e) => {
console.error(e);
return null;
});
},
setSuggestedMessages: async function (slug, messages) {
return fetch(`${API_BASE}/workspace/${slug}/suggested-messages`, {
method: "POST",
headers: baseHeaders(),
body: JSON.stringify({ messages }),
})
.then((res) => {
if (!res.ok) {
throw new Error(
res.statusText || "Error setting suggested messages."
);
}
return { success: true, ...res.json() };
})
.catch((e) => {
console.error(e);
return { success: false, error: e.message };
});
},
setPinForDocument: async function (slug, docPath, pinStatus) {
return fetch(`${API_BASE}/workspace/${slug}/update-pin`, {
method: "POST",
headers: baseHeaders(),
body: JSON.stringify({ docPath, pinStatus }),
})
.then((res) => {
if (!res.ok) {View on GitHub (pinned to 20f6d3546c)
Solutions
- Confirm the workspace slug still exists by re-fetching workspaces before saving.
- Send the messages payload exactly as the API expects (array of message strings).
- Check the Network tab status code to distinguish 401/403/404.
- Fix the latent bug: await res.json() before spreading it into the result.
Example fix
// before
return { success: true, ...res.json() }; // spreads a Promise, keys are garbage
// after
const data = await res.json();
return { success: true, ...data }; Defensive patterns
Strategy: validation
Validate before calling
// run before System.setSuggestedMessages
if (!slug) throw new Error('Workspace slug is required');
if (!Array.isArray(messages) || messages.some((m) => typeof m !== 'string')) {
throw new Error('messages must be an array of strings');
} Try / catch
const { success, error } = await Workspace.setSuggestedMessages(slug, messages);
if (!success) {
if (/not found/i.test(error || '')) await refreshWorkspaces(); // stale slug
showSaveError(error || 'Error setting suggested messages.');
} Prevention
- Derive the slug from freshly fetched workspace state, not cached component props.
- Validate the messages array shape client-side before posting.
- After any rename/delete of a workspace, invalidate screens still holding its slug.
When it happens
Trigger: Posting to a slug that no longer exists (workspace deleted or renamed → 404); a caller without permission for the workspace (403); a messages payload that is not the expected array shape (422); expired auth (401).
Common situations: Stale workspace slug held in component state after navigation or a rename; a non-manager role editing suggested messages; workspace removed concurrently in another tab.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Error downloading model: ${response.statusText}
- Error downloading model: ${response.statusText}
- No model router found for this workspace.
- Internal Server Error
- Bad Request
AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18).
Data as JSON: /api/errors/03d964018f9c357f.
Report an issue: GitHub.