{"record":{"id":"8e421c9d734af6c2","repo":"Mintplex-Labs/anything-llm","slug":"could-not-update-slash-command-preset","errorCode":null,"errorMessage":"Could not update slash command preset.","messagePattern":"Could not update slash command preset\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/system.js","lineNumber":749,"sourceCode":"        return data;\n      })\n      .then((res) => ({ preset: res.preset, error: null }))\n      .catch((e) => {\n        console.error(e);\n        return { preset: null, error: e.message };\n      });\n  },\n\n  updateSlashCommandPreset: async function (presetId, presetData) {\n    return await fetch(`${API_BASE}/system/slash-command-presets/${presetId}`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(presetData),\n    })\n      .then(async (res) => {\n        const data = await res.json();\n        if (!res.ok)\n          throw new Error(\n            data.message || \"Could not update slash command preset.\"\n          );\n        return data;\n      })\n      .then((res) => ({ preset: res.preset, error: null }))\n      .catch((e) => {\n        console.error(e);\n        return { preset: null, error: e.message };\n      });\n  },\n\n  deleteSlashCommandPreset: async function (presetId) {\n    return await fetch(`${API_BASE}/system/slash-command-presets/${presetId}`, {\n      method: \"DELETE\",\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (!res.ok) throw new Error(\"Could not delete slash command preset.\");","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/system.js#L731-L767","documentation":"Thrown when POST /system/slash-command-presets/:presetId returns non-2xx during an update. Same body-aware pattern as create (prefers data.message). The .catch returns { preset: null, error }. Note the route uses POST (not PATCH/PUT) for the update.","triggerScenarios":"presetId does not exist (404), presetId belongs to another user/workspace (403), the new presetData fails validation, or a stale presetId from a deleted row is reused.","commonSituations":"User edits a preset that was deleted in another tab; presetId is taken from stale component state after a refetch; concurrent delete-then-update race; route param encoding issues with special characters in the id.","solutions":["Confirm presetId still exists (refetch the preset list) before attempting the update.","Surface the returned error string — it is the server's data.message describing the specific failure.","If 403, verify the current user owns the preset or has admin scope.","Ensure the route is hit with POST (not PUT) to match the backend handler."],"exampleFix":"// before\nconst { preset, error } = await System.updateSlashCommandPreset(presetId, data);\n\n// after — verify existence then update\nconst existing = presets.find(p => p.id === presetId);\nif (!existing) return { preset: null, error: \"Preset no longer exists.\" };\nconst { preset, error } = await System.updateSlashCommandPreset(presetId, data);","handlingStrategy":"validation","validationCode":"// Ensure the preset still exists in the current list before updating.\nfunction presetExists(list, id) {\n  return list.some(p => p.id === id);\n}","typeGuard":"function isPresetUpdateResult(x): x is { preset: object; error: null } {\n  return x && x.preset !== null && x.error === null;\n}","tryCatchPattern":"const { preset, error } = await System.updateSlashCommandPreset(presetId, presetData);\nif (error) {\n  if (/not found|404/i.test(error)) refetchPresets(); // stale id\n  showToast(error);\n}","preventionTips":["Refetch the preset list when the user opens the editor to avoid stale ids.","Use the same POST method the handler expects (not PUT).","Handle 'not found' errors by refreshing the list rather than retrying blindly."],"tags":["frontend","api-client","validation","crud","slash-commands"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}