{"record":{"id":"c6cd421a6fdee94d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-sla-c6cd42","errorCode":"error-invalid-sla","errorMessage":"Invalid sla","messagePattern":"Invalid sla","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts","lineNumber":21,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { callbacks } from '../../../../server/lib/callbacks';\n\ncallbacks.add(\n\t'livechat.beforeInquiry',\n\tasync (extraData) => {\n\t\tconst { sla: slaSearchTerm, priority: prioritySearchTerm, ...props } = extraData;\n\t\tif (!slaSearchTerm && !prioritySearchTerm) {\n\t\t\treturn extraData;\n\t\t}\n\t\tlet sla: IOmnichannelServiceLevelAgreements | null = null;\n\t\tlet priority: ILivechatPriority | null = null;\n\t\tif (slaSearchTerm) {\n\t\t\tsla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(slaSearchTerm, {\n\t\t\t\tprojection: { dueTimeInMinutes: 1 },\n\t\t\t});\n\t\t\tif (!sla) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-sla', 'Invalid sla', {\n\t\t\t\t\tfunction: 'livechat.beforeInquiry',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (prioritySearchTerm) {\n\t\t\tpriority = await LivechatPriority.findOneByIdOrName(prioritySearchTerm, {\n\t\t\t\tprojection: { _id: 1, sortItem: 1 },\n\t\t\t});\n\t\t\tif (!priority) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-priority', 'Invalid priority', {\n\t\t\t\t\tfunction: 'livechat.beforeInquiry',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst ts = new Date();\n\t\tconst changes: Partial<ILivechatInquiryRecord> = {\n\t\t\tts,\n\t\t};","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts#L3-L39","documentation":"Thrown by the `beforeNewInquiry` omnichannel hook (MEDIUM priority, `livechat.beforeInquiry`) when `extraData.sla` is provided but `OmnichannelServiceLevelAgreements.findOneByIdOrName(slaSearchTerm)` returns null. The SLA referenced for a new inquiry does not exist. It is a `Meteor.Error` with code `error-invalid-sla` and metadata `{ function: 'livechat.beforeInquiry' }`.","triggerScenarios":"Creating a livechat inquiry with `extraData.sla` set to an id or name that matches no SLA document (deleted, never existed, typo, or wrong casing).","commonSituations":"Client sends a stale SLA id after the SLA was removed; REST API caller passes an SLA name that doesn't exist; SLA was renamed and the old name is still referenced.","solutions":["Verify the SLA exists via `OmnichannelServiceLevelAgreements.findOneByIdOrName(term)` before submitting the inquiry.","Omit `extraData.sla` if no SLA is required.","Re-create or correct the SLA record if it was deleted in error."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { OmnichannelServiceLevelAgreements } from '../../../../server/models';\n\nasync function slaExists(searchTerm: string): Promise<boolean> {\n\tif (!searchTerm) return true;\n\treturn Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(searchTerm, { projection: { dueTimeInMinutes: 1 } }));\n}","typeGuard":"function isInvalidSlaError(e: unknown): boolean {\n\treturn e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-invalid-sla';\n}","tryCatchPattern":"try {\n\tawait callbacks.run('livechat.beforeInquiry', extraData);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-invalid-sla') {\n\t\t// correct or omit extraData.sla\n\t}\n\tthrow e;\n}","preventionTips":["Validate SLA references (id/name) before creating inquiries.","Omit `extraData.sla` when no SLA is needed.","Keep client-side SLA lists in sync with server records."],"tags":["omnichannel","livechat","sla","validation","ee","meteor-error"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}