{"record":{"id":"7ce420b69c86624f","repo":"Mintplex-Labs/anything-llm","slug":"response-error-failed-to-create-agent-flow","errorCode":null,"errorMessage":"${response.error || \"Failed to create agent flow\"}","messagePattern":"\\$\\{response\\.error \\|\\| \"Failed to create agent flow\"\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/models/communityHub.js","lineNumber":198,"sourceCode":"        success: false,\n        error: e.message,\n      }));\n  },\n\n  /**\n   * Create a new agent flow in the community hub\n   * @param {Object} data - The agent flow data\n   * @returns {Promise<{success: boolean, error: string | null}>}\n   */\n  createAgentFlow: async (data) => {\n    return await fetch(`${API_BASE}/community-hub/agent-flow/create`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(data),\n    }).then(async (res) => {\n      const response = await res.json();\n      if (!res.ok)\n        throw new Error(response.error || \"Failed to create agent flow\");\n      return { success: true, error: null, itemId: response.item?.id };\n    });\n  },\n\n  /**\n   * Create a new slash command in the community hub\n   * @param {Object} data - The slash command data\n   * @param {string} data.name - The name of the command\n   * @param {string} data.description - The description of the command\n   * @param {string} data.command - The actual command text\n   * @param {string} data.prompt - The prompt for the command\n   * @param {string[]} data.tags - Array of tags\n   * @param {string} data.visibility - Either 'public' or 'private'\n   * @returns {Promise<{success: boolean, error: string | null}>}\n   */\n  createSlashCommand: async (data) => {\n    return await fetch(`${API_BASE}/community-hub/slash-command/create`, {\n      method: \"POST\",","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/communityHub.js#L180-L216","documentation":"Thrown from `createAgentFlow` on a non-ok `POST /api/community-hub/agent-flow/create`. Reads `response.error`, falling back to 'Failed to create agent flow'. Unlike sibling methods, this one has NO `.catch` — if `res.json()` rejects or the throw propagates, the promise rejects to the caller, so callers MUST handle the rejection themselves.","triggerScenarios":"Missing/invalid flow data (name, config), 401 non-admin, 409 duplicate flow name, 500 persistence error, malformed JSON body. Because there's no catch, any of these will reject the returned promise rather than return a `{ success, error }` object.","commonSituations":"Caller assumes a resolved `{success,error}` shape (like the sibling methods) and hits an unhandled rejection; incomplete flow config submitted; session expired.","solutions":["Wrap the call in try/catch (or `.catch`) since this method does not catch internally.","Validate the flow data (name non-empty, config is a serializable object) before posting.","Read the rejection's message for the server's reason.","Align this method with its siblings by adding a `.catch` returning `{ success: false, error: e.message }` for consistent caller handling."],"exampleFix":"// before — no catch on the model; caller may get an unhandled rejection\nconst result = await CommunityHub.createAgentFlow(data);\n\n// after — caller must catch; and consider patching the model for consistency\ntry {\n  const result = await CommunityHub.createAgentFlow(data);\n  if (!result.success) throw new Error(result.error || 'Failed to create agent flow');\n} catch (e) {\n  // handle e.message (server error or network failure)\n}\n\n// also patch the model (mirrors createSystemPrompt):\n//   .catch((e) => ({ success: false, error: e.message }))","handlingStrategy":"try-catch","validationCode":"function validateAgentFlowPayload(data) {\n  if (!data || typeof data !== 'object') throw new Error('Agent flow data is required');\n  if (typeof data.name !== 'string' || !data.name.trim()) throw new Error('Agent flow name is required');\n  if (!data.config || typeof data.config !== 'object') throw new Error('Agent flow config is required');\n}","typeGuard":"function isAgentFlowPayload(v) {\n  return !!v && typeof v === 'object' && typeof v.name === 'string' && v.name.trim().length > 0 && !!v.config && typeof v.config === 'object';\n}","tryCatchPattern":"// IMPORTANT: this model does NOT catch internally — wrap the call:\ntry {\n  const result = await CommunityHub.createAgentFlow(data);\n  if (!result?.success) showToast(result?.error || 'Failed to create agent flow');\n} catch (e) {\n  showToast(e.message); // network/parse failure\n}","preventionTips":["Always wrap createAgentFlow in try/catch — it lacks the `.catch` its siblings have.","Patch the model to add `.catch((e) => ({ success: false, error: e.message }))` for consistency.","Validate name + config before posting."],"tags":["frontend","community-hub","agent-flows","validation","fetch","unhandled-rejection"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}