RocketChat/Rocket.Chat · error · Meteor.Error

error-forwarding-department-target-not-allowed

error-forwarding-department-target-not-allowed

Error message

The forwarding to the target department is not allowed.

What it means

Thrown by the `beforeForwardRoomToDepartment` omnichannel hook (HIGH priority) when the current department has a non-empty `departmentsAllowedToForward` list that does NOT include the target department's `_id`. It enforces per-department forwarding allowlists for livechat transfers. It is a `Meteor.Error` with code `error-forwarding-department-target-not-allowed`.

Source

Thrown at apps/meteor/ee/server/hooks/omnichannel/beforeForwardRoomToDepartment.ts:32

		const { departmentId } = room;
		if (!departmentId) {
			return options;
		}
		const { department: departmentToTransfer } = transferData;
		const currentDepartment = await LivechatDepartment.findOneById<Pick<ILivechatDepartment, 'departmentsAllowedToForward'>>(departmentId, {
			projection: { departmentsAllowedToForward: 1 },
		});
		if (!currentDepartment) {
			return options;
		}
		const { departmentsAllowedToForward } = currentDepartment;
		const isAllowedToTransfer =
			!departmentsAllowedToForward?.length ||
			(Array.isArray(departmentsAllowedToForward) && departmentsAllowedToForward.includes(departmentToTransfer._id));
		if (isAllowedToTransfer) {
			return options;
		}
		throw new Meteor.Error('error-forwarding-department-target-not-allowed', 'The forwarding to the target department is not allowed.');
	},
	callbacks.priority.HIGH,
	'livechat-before-forward-room-to-department',
);

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Add the target department's `_id` to the source department's `departmentsAllowedToForward` list.
  2. Transfer to a department that is already in the allowed list.
  3. Clear/relax the `departmentsAllowedToForward` list if forwarding to any department should be permitted.
Defensive patterns

Strategy: validation

Validate before calling

async function canForwardTo(sourceDeptId: string, targetDeptId: string): Promise<boolean> {
	const dept = await LivechatDepartmentRaw.findOneById(sourceDeptId, { projection: { departmentsAllowedToForward: 1 } });
	const allowed = dept?.departmentsAllowedToForward;
	return !allowed?.length || (Array.isArray(allowed) && allowed.includes(targetDeptId));
}

Type guard

function isForwardingDepartmentTargetNotAllowedError(e: unknown): boolean {
	return e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-forwarding-department-target-not-allowed';
}

Try / catch

try {
	await callbacks.run('livechat.beforeForwardRoomToDepartment', options);
} catch (e) {
	if (e instanceof Meteor.Error && e.error === 'error-forwarding-department-target-not-allowed') {
		// add target dept to allowlist or pick an allowed dept
	}
	throw e;
}

Prevention

When it happens

Trigger: Forwarding/transferring a livechat room to a department whose `_id` is not in the source department's `departmentsAllowedToForward` array (and that array is non-empty). If the source department is not found, the hook allows the forward.

Common situations: Admin configured a restrictive forwarding allowlist on a department and an agent tries to transfer to a disallowed department; department was renamed/recreated (new `_id`) but the allowlist still references the old id; misconfigured allowlist during department setup.

Related errors


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