RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-sla

error-invalid-sla

Error message

Invalid sla

What it means

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' }`.

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 f9d3ec372b)

Solutions

  1. Verify the SLA exists via `OmnichannelServiceLevelAgreements.findOneByIdOrName(term)` before creating the room.
  2. Omit `extraData.sla` to create the room without an SLA.
  3. Recreate the SLA record if it was removed in error.
Defensive patterns

Strategy: validation

Validate before calling

import { OmnichannelServiceLevelAgreements } from '../../../../server/models';

async function slaExistsForRoom(searchTerm: string): Promise<boolean> {
	if (!searchTerm) return true;
	return Boolean(await OmnichannelServiceLevelAgreements.findOneByIdOrName(searchTerm));
}

Type guard

function isInvalidSlaRoomError(e: unknown): boolean {
	return e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-invalid-sla' && (e as Meteor.Error).details?.function === 'livechat.beforeRoom';
}

Try / catch

try {
	await beforeNewRoom.run(roomInfo, extraData);
} catch (e) {
	if (e instanceof Meteor.Error && e.error === 'error-invalid-sla') {
		// correct or omit extraData.sla for room creation
	}
	throw e;
}

Prevention

When it happens

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

Common situations: 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.

Related errors


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