Mintplex-Labs/anything-llm · error
${res.error || "Failed to toggle flow"}
Error message
${res.error || "Failed to toggle flow"} What it means
Thrown from `toggleFlow` on a non-ok `POST /api/agent-flows/:uuid/toggle`. Same defect as 51-53: `res.error` is always undefined on a `Response`, so the message always becomes 'Failed to toggle flow'. This variant is wrapped in try/catch and returns `{ success: false, error: error.message }`.
Source
Thrown at frontend/src/models/agentFlows.js:137
/**
* Toggle a flow's active status
* @param {string} uuid - The UUID of the flow to toggle
* @param {boolean} active - The new active status
* @returns {Promise<{success: boolean, error: string | null}>}
*/
toggleFlow: async (uuid, active) => {
try {
const result = await fetch(`${API_BASE}/agent-flows/${uuid}/toggle`, {
method: "POST",
headers: {
...baseHeaders(),
"Content-Type": "application/json",
},
body: JSON.stringify({ active }),
})
.then((res) => {
if (!res.ok) throw new Error(res.error || "Failed to toggle flow");
return res;
})
.then((res) => res.json());
return { success: true, flow: result.flow };
} catch (error) {
console.error("Failed to toggle flow:", error);
return { success: false, error: error.message };
}
},
};
export default AgentFlows;
View on GitHub (pinned to 526360e320)
Solutions
- Patch to read `response.error` from the parsed JSON body.
- On 404, refresh the flow list; on 401, re-authenticate.
- Debounce/disable the toggle button until the request resolves to avoid races.
- Inspect the network response body for the real error during debugging.
Example fix
// before
.then((res) => {
if (!res.ok) throw new Error(res.error || 'Failed to toggle flow');
return res;
})
// after
.then(async (res) => {
const response = await res.json();
if (!res.ok) throw new Error(response?.error || `Failed to toggle flow (HTTP ${res.status})`);
return response;
}) Defensive patterns
Strategy: try-catch
Validate before calling
function validateToggle(uuid, active) {
if (!/^[0-9a-fA-F-]{36}$/.test(String(uuid || ''))) throw new Error('Valid flow UUID required');
if (typeof active !== 'boolean') throw new Error('active must be boolean');
} Type guard
function isUuid(v) { return /^[0-9a-fA-F-]{36}$/.test(String(v || '')); } Try / catch
const { success, error, flow } = await AgentFlows.toggleFlow(uuid, active);
if (!success) {
if (/404|not found/i.test(error)) { await refreshFlows(); return; }
showToast(error);
} Prevention
- Patch the model to read `response.error` from the JSON body.
- Debounce/disable the toggle button until the request resolves to avoid races.
- Refresh the flow list on 404.
When it happens
Trigger: Toggling a deleted/non-existent flow (404), 401 expired session, invalid `active` payload, backend 500, race with concurrent delete.
Common situations: User toggles a flow that was removed elsewhere; session expires mid-session; rapid toggle clicks race.
Related errors
- ${res.error || "Failed to save flow"}
- ${res.error || "Failed to get flow"}
- ${res.error || "Failed to delete flow"}
- ${res.statusText || "Error fetching api keys."}
- ${res.statusText || "Error generating api key."}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/fafe85308e044a9a.
Report an issue: GitHub.