{"record":{"id":"e412f2e4be35011d","repo":"Mintplex-Labs/anything-llm","slug":"res-statustext","errorCode":null,"errorMessage":"res.statusText","messagePattern":"res\\.statusText","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/models/embed.js","lineNumber":48,"sourceCode":"    return await fetch(`${API_BASE}/embed/update/${embedId}`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(data),\n    })\n      .then((res) => res.json())\n      .catch((e) => {\n        console.error(e);\n        return { success: false, error: e.message };\n      });\n  },\n  deleteEmbed: async (embedId) => {\n    return await fetch(`${API_BASE}/embed/${embedId}`, {\n      method: \"DELETE\",\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (res.ok) return { success: true, error: null };\n        throw new Error(res.statusText);\n      })\n      .catch((e) => {\n        console.error(e);\n        return { success: true, error: e.message };\n      });\n  },\n  chats: async (offset = 0) => {\n    return await fetch(`${API_BASE}/embed/chats`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify({ offset }),\n    })\n      .then((res) => res.json())\n      .catch((e) => {\n        console.error(e);\n        return [];\n      });\n  },","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/embed.js#L30-L66","documentation":"Thrown by deleteEmbed when the DELETE to /embed/:embedId returns a non-OK status; the thrown message is the HTTP statusText (e.g. 'Not Found', 'Unauthorized'). Critically, the .catch returns {success: true, error: e.message} - the success:true is a defect, so callers that branch on .success will treat a failed delete as successful and silently leak embeds. Treat both the error field and the success flag with suspicion here.","triggerScenarios":"embedId does not exist (404 Not Found); caller's session lacks permission to delete this embed (401/403); server-side error (500); network failure mid-request.","commonSituations":"User already deleted the embed in another tab and clicks delete again; non-admin user attempting to delete another user's embed; transient 5xx during deploy; embed was hard-deleted by a cleanup job between page load and click.","solutions":["Do NOT trust result.success alone - also check result.error before considering the delete done.","If statusText is 'Not Found', refresh the embed list and remove the stale row.","If 'Unauthorized'/'Forbidden', re-authenticate or surface a permissions message.","Patch the model: the catch should return {success:false, error:e.message}."],"exampleFix":"// before (bug: returns success:true on failure)\n.catch((e) => {\n  console.error(e);\n  return { success: true, error: e.message };\n});\n\n// after\ncatch((e) => {\n  console.error(e);\n  return { success: false, error: e.message };\n});\n\n// caller-side guard until the model is fixed:\nconst res = await Embed.deleteEmbed(id);\nconst deleted = res.success && !res.error;","handlingStrategy":"type-guard","validationCode":"function validateEmbedId(id) {\n  if (!id || typeof id !== 'string') return 'embedId is required';\n  return null;\n}","typeGuard":"// Until the model bug (success:true on failure) is fixed, guard on BOTH fields:\n/** @param {{success:boolean, error:string|null}} r */\nfunction deleteSucceeded(r) {\n  return r.success === true && !r.error;\n}","tryCatchPattern":"const res = await Embed.deleteEmbed(embedId);\nif (!deleteSucceeded(res)) {\n  // res.error carries statusText, e.g. 'Not Found' or 'Unauthorized'\n  handleDeleteFailure(res.error);\n}","preventionTips":["Do NOT trust result.success alone - the model returns success:true on failure (bug).","Patch the model's .catch to return { success:false, error:e.message }.","Handle 404 specially: the embed may already be gone (idempotent delete).","Re-authenticate on 401/403 statusText."],"tags":["api","embed","bug","error-handling","auth"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}