{"record":{"id":"ce1aa0568803ef21","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-sla","errorCode":null,"errorMessage":"error-invalid-sla","messagePattern":"error-invalid-sla","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts","lineNumber":13,"sourceCode":"import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';\n\nimport { updateRoomSLA } from './sla';\n\nexport async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {\n\tconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\n\tif (!inquiry || inquiry.status !== 'queued') {\n\t\tthrow new Error('error-invalid-inquiry');\n\t}\n\n\tconst slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));\n\tif (!slaData) {\n\t\tthrow new Error('error-invalid-sla');\n\t}\n\n\tconst user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });\n\tif (!user?.username) {\n\t\tthrow new Error('error-invalid-user');\n\t}\n\n\tawait updateRoomSLA(\n\t\troomId,\n\t\t{\n\t\t\t_id: user._id,\n\t\t\tname: user.name || '',\n\t\t\tusername: user.username,\n\t\t},\n\t\tslaData,\n\t);\n}\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts#L1-L31","documentation":"Thrown by setSLAToInquiry when the supplied sla identifier does not resolve to an OmnichannelServiceLevelAgreements document (looked up by _id or name). The SLA policy must exist before it can be attached to an inquiry. Plain Error, code 'error-invalid-sla'.","triggerScenarios":"Calling setSLAToInquiry with an sla value that is neither an existing SLA _id nor name; SLA was deleted between the UI listing it and the assignment; typo in the SLA name; sla omitted-but-truthy edge (empty string).","commonSituations":"SLA policy renamed/deleted by an admin; stale dropdown in the UI; copy-paste error in the sla field; SLA seeded in a different workspace.","solutions":["Verify the SLA exists via OmnichannelServiceLevelAgreements.findOneByIdOrName(sla) before assigning.","Refresh the SLA list in the UI before selection.","Pass the SLA _id (preferred) rather than the name to avoid rename collisions.","Handle a missing SLA as a soft error and prompt the user to re-pick."],"exampleFix":"// before: pass user-typed name\nawait setSLAtToInquiry({ userId, roomId, sla: userInput });\n\n// after: validate existence\nconst slaDoc = await OmnichannelServiceLevelAgreements.findOneByIdOrName(userInput);\nif (!slaDoc) throw new ClientError('Unknown SLA.');\nawait setSLAToInquiry({ userId, roomId, sla: slaDoc._id });","handlingStrategy":"validation","validationCode":"// Validate the SLA exists before assigning\nimport { OmnichannelServiceLevelAgreements } from '@rocket.chat/models';\nconst slaDoc = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));\nif (!slaDoc) {\n  throw new ClientError('Unknown SLA');\n}\nawait setSLAToInquiry({ userId, roomId, sla: slaDoc._id });","typeGuard":null,"tryCatchPattern":"try {\n  await setSLAToInquiry({ userId, roomId, sla });\n} catch (e) {\n  if (e.message === 'error-invalid-sla') {\n    // refresh the SLA list and prompt the user to re-pick\n    await refreshSlaOptions();\n    return;\n  }\n  throw e;\n}","preventionTips":["Pass the SLA _id rather than the name to avoid rename collisions.","Refresh SLA dropdowns from the API before each assignment session."],"tags":["omnichannel","sla","livechat","validation"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}