RocketChat/Rocket.Chat · error · Error

error-invalid-sla

Error message

error-invalid-sla

What it means

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

Source

Thrown at apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts:13

import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';

import { updateRoomSLA } from './sla';

export async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {
	const inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });
	if (!inquiry || inquiry.status !== 'queued') {
		throw new Error('error-invalid-inquiry');
	}

	const slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));
	if (!slaData) {
		throw new Error('error-invalid-sla');
	}

	const user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });
	if (!user?.username) {
		throw new Error('error-invalid-user');
	}

	await updateRoomSLA(
		roomId,
		{
			_id: user._id,
			name: user.name || '',
			username: user.username,
		},
		slaData,
	);
}

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Verify the SLA exists via OmnichannelServiceLevelAgreements.findOneByIdOrName(sla) before assigning.
  2. Refresh the SLA list in the UI before selection.
  3. Pass the SLA _id (preferred) rather than the name to avoid rename collisions.
  4. Handle a missing SLA as a soft error and prompt the user to re-pick.

Example fix

// before: pass user-typed name
await setSLAtToInquiry({ userId, roomId, sla: userInput });

// after: validate existence
const slaDoc = await OmnichannelServiceLevelAgreements.findOneByIdOrName(userInput);
if (!slaDoc) throw new ClientError('Unknown SLA.');
await setSLAToInquiry({ userId, roomId, sla: slaDoc._id });
Defensive patterns

Strategy: validation

Validate before calling

// Validate the SLA exists before assigning
import { OmnichannelServiceLevelAgreements } from '@rocket.chat/models';
const slaDoc = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));
if (!slaDoc) {
  throw new ClientError('Unknown SLA');
}
await setSLAToInquiry({ userId, roomId, sla: slaDoc._id });

Try / catch

try {
  await setSLAToInquiry({ userId, roomId, sla });
} catch (e) {
  if (e.message === 'error-invalid-sla') {
    // refresh the SLA list and prompt the user to re-pick
    await refreshSlaOptions();
    return;
  }
  throw e;
}

Prevention

When it happens

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

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

Related errors


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