{"record":{"id":"03d964018f9c357f","repo":"Mintplex-Labs/anything-llm","slug":"res-statustext-error-setting-suggested-message","errorCode":null,"errorMessage":"res.statusText || \"Error setting suggested messages.\"","messagePattern":"res\\.statusText \\|\\| \"Error setting suggested messages\\.\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/workspace.js","lineNumber":338,"sourceCode":"      .then((res) => {\n        if (!res.ok) throw new Error(\"Could not fetch suggested messages.\");\n        return res.json();\n      })\n      .then((res) => res.suggestedMessages)\n      .catch((e) => {\n        console.error(e);\n        return null;\n      });\n  },\n  setSuggestedMessages: async function (slug, messages) {\n    return fetch(`${API_BASE}/workspace/${slug}/suggested-messages`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify({ messages }),\n    })\n      .then((res) => {\n        if (!res.ok) {\n          throw new Error(\n            res.statusText || \"Error setting suggested messages.\"\n          );\n        }\n        return { success: true, ...res.json() };\n      })\n      .catch((e) => {\n        console.error(e);\n        return { success: false, error: e.message };\n      });\n  },\n  setPinForDocument: async function (slug, docPath, pinStatus) {\n    return fetch(`${API_BASE}/workspace/${slug}/update-pin`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify({ docPath, pinStatus }),\n    })\n      .then((res) => {\n        if (!res.ok) {","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/frontend/src/models/workspace.js#L320-L356","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nreturn { success: true, ...res.json() }; // spreads a Promise, keys are garbage\n\n// after\nconst data = await res.json();\nreturn { success: true, ...data };","handlingStrategy":"validation","validationCode":"// run before System.setSuggestedMessages\nif (!slug) throw new Error('Workspace slug is required');\nif (!Array.isArray(messages) || messages.some((m) => typeof m !== 'string')) {\n  throw new Error('messages must be an array of strings');\n}","typeGuard":null,"tryCatchPattern":"const { success, error } = await Workspace.setSuggestedMessages(slug, messages);\nif (!success) {\n  if (/not found/i.test(error || '')) await refreshWorkspaces(); // stale slug\n  showSaveError(error || 'Error setting suggested messages.');\n}","preventionTips":["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."],"tags":["anythingllm","workspace","suggested-messages","http"],"backgroundTag":"http-request-failed","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}