{"record":{"id":"cd01daaed26754d8","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-priority-cd01da","errorCode":"error-invalid-priority","errorMessage":"Invalid priority","messagePattern":"Invalid priority","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts","lineNumber":31,"sourceCode":"\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};\n\t\tif (sla) {\n\t\t\tchanges.slaId = sla._id;\n\t\t\tchanges.estimatedWaitingTimeQueue = sla.dueTimeInMinutes;\n\t\t}\n\t\tif (priority) {\n\t\t\tchanges.priorityId = priority._id;\n\t\t\tchanges.priorityWeight = priority.sortItem;\n\t\t}\n\t\treturn { ...props, ...changes };\n\t},","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/omnichannel/beforeNewInquiry.ts#L13-L49","documentation":"Thrown by the `beforeNewInquiry` omnichannel hook when `extraData.priority` is provided but `LivechatPriority.findOneByIdOrName(prioritySearchTerm)` returns null. The priority referenced for a new inquiry does not exist. It is a `Meteor.Error` with code `error-invalid-priority` and metadata `{ function: 'livechat.beforeInquiry' }`.","triggerScenarios":"Creating a livechat inquiry with `extraData.priority` set to an id or name that matches no priority document.","commonSituations":"Client sends a stale priority id after the priority was removed/disabled; REST API caller passes a priority name that doesn't exist; priority disabled but still referenced by integrations.","solutions":["Verify the priority exists via `LivechatPriority.findOneByIdOrName(term)` before submitting the inquiry.","Omit `extraData.priority` if no priority is required.","Re-enable or recreate the priority record if it was disabled in error."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { LivechatPriority } from '../../../../server/models';\n\nasync function priorityExists(searchTerm: string): Promise<boolean> {\n\tif (!searchTerm) return true;\n\treturn Boolean(await LivechatPriority.findOneByIdOrName(searchTerm, { projection: { _id: 1, sortItem: 1 } }));\n}","typeGuard":"function isInvalidPriorityError(e: unknown): boolean {\n\treturn e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-invalid-priority';\n}","tryCatchPattern":"try {\n\tawait callbacks.run('livechat.beforeInquiry', extraData);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-invalid-priority') {\n\t\t// correct or omit extraData.priority\n\t}\n\tthrow e;\n}","preventionTips":["Validate priority references (id/name) before creating inquiries.","Omit `extraData.priority` when no priority is needed.","Re-enable disabled priorities or remove stale references in integrations."],"tags":["omnichannel","livechat","priority","validation","ee","meteor-error"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}