{"record":{"id":"fafe85308e044a9a","repo":"Mintplex-Labs/anything-llm","slug":"res-error-failed-to-toggle-flow","errorCode":null,"errorMessage":"${res.error || \"Failed to toggle flow\"}","messagePattern":"\\$\\{res\\.error \\|\\| \"Failed to toggle flow\"\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/models/agentFlows.js","lineNumber":137,"sourceCode":"\n  /**\n   * Toggle a flow's active status\n   * @param {string} uuid - The UUID of the flow to toggle\n   * @param {boolean} active - The new active status\n   * @returns {Promise<{success: boolean, error: string | null}>}\n   */\n  toggleFlow: async (uuid, active) => {\n    try {\n      const result = await fetch(`${API_BASE}/agent-flows/${uuid}/toggle`, {\n        method: \"POST\",\n        headers: {\n          ...baseHeaders(),\n          \"Content-Type\": \"application/json\",\n        },\n        body: JSON.stringify({ active }),\n      })\n        .then((res) => {\n          if (!res.ok) throw new Error(res.error || \"Failed to toggle flow\");\n          return res;\n        })\n        .then((res) => res.json());\n      return { success: true, flow: result.flow };\n    } catch (error) {\n      console.error(\"Failed to toggle flow:\", error);\n      return { success: false, error: error.message };\n    }\n  },\n};\n\nexport default AgentFlows;\n","sourceCodeStart":119,"sourceCodeEnd":150,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/agentFlows.js#L119-L150","documentation":"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 }`.","triggerScenarios":"Toggling a deleted/non-existent flow (404), 401 expired session, invalid `active` payload, backend 500, race with concurrent delete.","commonSituations":"User toggles a flow that was removed elsewhere; session expires mid-session; rapid toggle clicks race.","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."],"exampleFix":"// before\n.then((res) => {\n  if (!res.ok) throw new Error(res.error || 'Failed to toggle flow');\n  return res;\n})\n\n// after\n.then(async (res) => {\n  const response = await res.json();\n  if (!res.ok) throw new Error(response?.error || `Failed to toggle flow (HTTP ${res.status})`);\n  return response;\n})","handlingStrategy":"try-catch","validationCode":"function validateToggle(uuid, active) {\n  if (!/^[0-9a-fA-F-]{36}$/.test(String(uuid || ''))) throw new Error('Valid flow UUID required');\n  if (typeof active !== 'boolean') throw new Error('active must be boolean');\n}","typeGuard":"function isUuid(v) { return /^[0-9a-fA-F-]{36}$/.test(String(v || '')); }","tryCatchPattern":"const { success, error, flow } = await AgentFlows.toggleFlow(uuid, active);\nif (!success) {\n  if (/404|not found/i.test(error)) { await refreshFlows(); return; }\n  showToast(error);\n}","preventionTips":["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."],"tags":["frontend","agent-flows","fetch","bug","network"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}