{"record":{"id":"9623fd51c8155230","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-sla-9623fd","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/beforeNewRoom.ts","lineNumber":26,"sourceCode":"export const beforeNewRoomPatched = async (\n\t_next: any,\n\troomInfo: IOmnichannelRoomInfo,\n\textraData?: IOmnichannelRoomExtraData,\n): Promise<Partial<IOmnichannelRoom>> => {\n\tif (!extraData) {\n\t\treturn roomInfo;\n\t}\n\n\tconst { sla: searchTerm, customFields } = extraData;\n\tconst roomInfoWithExtraData = { ...roomInfo, ...(isPlainObject(customFields) && { customFields }) };\n\n\tif (!searchTerm) {\n\t\treturn roomInfoWithExtraData;\n\t}\n\n\tconst sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(searchTerm);\n\tif (!sla) {\n\t\tthrow new Meteor.Error('error-invalid-sla', 'Invalid sla', {\n\t\t\tfunction: 'livechat.beforeRoom',\n\t\t});\n\t}\n\n\tconst { _id: slaId } = sla;\n\treturn { ...roomInfoWithExtraData, slaId };\n};\n\nbeforeNewRoom.patch(beforeNewRoomPatched);\n","sourceCodeStart":8,"sourceCodeEnd":36,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/omnichannel/beforeNewRoom.ts#L8-L36","documentation":"Thrown by the `beforeNewRoomPatched` omnichannel hook (run via `beforeNewRoom.patch`) when `extraData.sla` is provided but `OmnichannelServiceLevelAgreements.findOneByIdOrName(searchTerm)` returns null. The SLA referenced for a new livechat room does not exist. It is a `Meteor.Error` with code `error-invalid-sla` and metadata `{ function: 'livechat.beforeRoom' }`.","triggerScenarios":"Creating a livechat room with `extraData.sla` set to an id or name that matches no SLA document. Note this is the room-creation path (different `function` tag from the inquiry path).","commonSituations":"SLA deleted after a visitor session started but before room creation; REST API creates a room with a non-existent SLA id; integrations pass a stale SLA reference.","solutions":["Verify the SLA exists via `OmnichannelServiceLevelAgreements.findOneByIdOrName(term)` before creating the room.","Omit `extraData.sla` to create the room without an SLA.","Recreate the SLA record if it was removed in error."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { OmnichannelServiceLevelAgreements } from '../../../../server/models';\n\nasync function slaExistsForRoom(searchTerm: string): Promise<boolean> {\n\tif (!searchTerm) return true;\n\treturn Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(searchTerm));\n}","typeGuard":"function isInvalidSlaRoomError(e: unknown): boolean {\n\treturn e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-invalid-sla' && (e as Meteor.Error).details?.function === 'livechat.beforeRoom';\n}","tryCatchPattern":"try {\n\tawait beforeNewRoom.run(roomInfo, extraData);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-invalid-sla') {\n\t\t// correct or omit extraData.sla for room creation\n\t}\n\tthrow e;\n}","preventionTips":["Validate SLA references before creating livechat rooms.","Omit `extraData.sla` when not required.","Reconcile SLA records after deletions/renames."],"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"}