{"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/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/hooks/omnichannel/beforeNewRoom.ts#L8-L36","documentation":"Thrown by the beforeNewRoom hook (livechat.beforeRoom) when room creation data includes an sla search term that OmnichannelServiceLevelAgreements.findOneByIdOrName cannot resolve. Unlike the inquiry hook, this runs before the room document is created, mapping the term to a slaId on the room; a bad reference stops room creation.","triggerScenarios":"Creating a livechat room (visitor chat) with extraData.sla referencing a deleted/unknown SLA id or name; REST/API clients or apps passing stale SLA identifiers picked up from another environment.","commonSituations":"SLA deleted or renamed after the website/livechat widget configuration cached it; environment migrations losing SLA collections while configs keep the old ids.","solutions":["Look up the SLA via the livechat SLA API and pass its exact _id or name","Recreate or rename-fix the SLA so the stored reference resolves","Omit sla from extraData to create the room without an SLA"],"exampleFix":"// before: room creation with an unvalidated sla term\nawait createRoom({ ...roomInfo, extraData: { sla: 'platinum' } });\n\n// after: resolve the SLA first\nconst sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName('platinum');\nif (!sla) throw new Error('Unknown SLA: platinum');\nawait createRoom({ ...roomInfo, extraData: { sla: 'platinum' } });","handlingStrategy":"validation","validationCode":"const roomSlaIsValid = async (term: string): Promise<boolean> =>\n  Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(term, { projection: { _id: 1 } }));","typeGuard":null,"tryCatchPattern":"try {\n  await createRoom({ ...roomInfo, extraData: { sla: term } });\n} catch (err: any) {\n  if (err?.error === 'error-invalid-sla' && err?.details?.function === 'livechat.beforeRoom') {\n    // drop or fix the sla term and recreate the room\n  }\n  throw err;\n}","preventionTips":["Resolve SLA ids server-side before room creation instead of trusting widget payloads","Keep SLA references in omnichannel triggers synced with live SLA records","Note this hook fires before the room exists, so failures leave no partial room"],"tags":["omnichannel","livechat","sla","room-creation","entity-not-found"],"backgroundTag":"sla-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}