RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-sla

error-invalid-sla

Error message

Invalid sla

What it means

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.

Solutions

  1. Look up the SLA via the livechat SLA API and pass its exact _id or name
  2. Recreate or rename-fix the SLA so the stored reference resolves
  3. Omit sla from extraData to create the room without an SLA

Example fix

// before: room creation with an unvalidated sla term
await createRoom({ ...roomInfo, extraData: { sla: 'platinum' } });

// after: resolve the SLA first
const sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName('platinum');
if (!sla) throw new Error('Unknown SLA: platinum');
await createRoom({ ...roomInfo, extraData: { sla: 'platinum' } });
Defensive patterns

Strategy: validation

Validate before calling

const roomSlaIsValid = async (term: string): Promise<boolean> =>
  Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(term, { projection: { _id: 1 } }));

Try / catch

try {
  await createRoom({ ...roomInfo, extraData: { sla: term } });
} catch (err: any) {
  if (err?.error === 'error-invalid-sla' && err?.details?.function === 'livechat.beforeRoom') {
    // drop or fix the sla term and recreate the room
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: SLA deleted or renamed after the website/livechat widget configuration cached it; environment migrations losing SLA collections while configs keep the old ids.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/9623fd51c8155230. Report an issue: GitHub.

Appendix: source

Thrown at apps/meteor/ee/server/hooks/omnichannel/beforeNewRoom.ts:26

export const beforeNewRoomPatched = async (
	_next: any,
	roomInfo: IOmnichannelRoomInfo,
	extraData?: IOmnichannelRoomExtraData,
): Promise<Partial<IOmnichannelRoom>> => {
	if (!extraData) {
		return roomInfo;
	}

	const { sla: searchTerm, customFields } = extraData;
	const roomInfoWithExtraData = { ...roomInfo, ...(isPlainObject(customFields) && { customFields }) };

	if (!searchTerm) {
		return roomInfoWithExtraData;
	}

	const sla = await OmnichannelServiceLevelAgreements.findOneByIdOrName(searchTerm);
	if (!sla) {
		throw new Meteor.Error('error-invalid-sla', 'Invalid sla', {
			function: 'livechat.beforeRoom',
		});
	}

	const { _id: slaId } = sla;
	return { ...roomInfoWithExtraData, slaId };
};

beforeNewRoom.patch(beforeNewRoomPatched);

View on GitHub (pinned to b2c16d5842)