{"record":{"id":"bf7d95932ffecbde","repo":"RocketChat/Rocket.Chat","slug":"error-canned-response-not-found","errorCode":"error-canned-response-not-found","errorMessage":"Canned Response not found","messagePattern":"Canned Response not found","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/meteor-methods/removeCannedResponse.ts","lineNumber":19,"sourceCode":"import { CannedResponse } from '@rocket.chat/models';\nimport { check } from 'meteor/check';\nimport { Meteor } from 'meteor/meteor';\n\nimport { hasPermissionAsync } from '../../../server/lib/authorization/hasPermission';\nimport notifications from '../../../server/lib/notifications/core/lib/Notifications';\n\nexport const removeCannedResponse = async (uid: string, _id: string): Promise<void> => {\n\tif (!(await hasPermissionAsync(uid, 'remove-canned-responses'))) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', {\n\t\t\tmethod: 'removeCannedResponse',\n\t\t});\n\t}\n\n\tcheck(_id, String);\n\n\tconst cannedResponse = await CannedResponse.findOneById(_id);\n\tif (!cannedResponse) {\n\t\tthrow new Meteor.Error('error-canned-response-not-found', 'Canned Response not found', {\n\t\t\tmethod: 'removeCannedResponse',\n\t\t});\n\t}\n\n\tnotifications.streamCannedResponses.emit('canned-responses', { type: 'removed', _id });\n\n\tawait CannedResponse.removeById(_id);\n};\n","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/meteor-methods/removeCannedResponse.ts#L1-L28","documentation":"Thrown by removeCannedResponse when CannedResponse.findOneById(_id) returns null. The canned response id supplied does not match any document, so there is nothing to delete. Code is 'error-canned-response-not-found'.","triggerScenarios":"Calling removeCannedResponse with an _id that was already deleted, never existed, or is mistyped; concurrent delete by another user.","commonSituations":"Stale list in the UI after a delete; duplicate delete clicks; id copied/truncated incorrectly.","solutions":["Refresh the canned-response list after a delete and remove the row optimistically or on confirmation.","Treat 'not found' as success for idempotent delete UX (the resource is gone either way).","Validate the id exists before showing the delete confirmation."],"exampleFix":"// before\nawait removeCannedResponse(uid, _id);\n\n// after\nconst existing = await CannedResponse.findOneById(_id);\nif (!existing) return { alreadyDeleted: true };\nawait removeCannedResponse(uid, _id);","handlingStrategy":"try-catch","validationCode":"const existing = await CannedResponse.findOneById(_id);\nif (!existing) return { alreadyDeleted: true };\nawait removeCannedResponse(uid, _id);","typeGuard":null,"tryCatchPattern":"try {\n  await removeCannedResponse(uid, _id);\n} catch (e) {\n  if (isMeteorError(e, 'error-canned-response-not-found')) return;\n  throw e;\n}","preventionTips":["Treat 'not found' as idempotent success in the UI.","Refresh the list after a delete.","Prevent duplicate delete submissions."],"tags":["canned-responses","not-found","validation"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}