RocketChat/Rocket.Chat · error · Meteor.Error

error-unit-not-found

error-unit-not-found

Error message

Error! No Active Business Unit found with id: ${businessUnit}

What it means

This Enterprise patch on checkUnitsFromUser runs when a businessUnit id is supplied: it computes the units the user may see (getUnitsFromUser(userId)) and calls LivechatUnit.findOneById(businessUnit, { projection: { _id: 1 } }, { unitsFromUser }). The unitsFromUser constraint restricts the lookup to the user's own units, so the throw Meteor.Error('error-unit-not-found', 'Error! No Active Business Unit found with id: ...') means the unit does not exist, is not active, or is outside the user's unit membership.

Solutions

  1. Verify the businessUnit id exists and the unit is active in Administration > Omnichannel, then correct the id being sent.
  2. Ensure the affected user belongs to a department under that unit so getUnitsFromUser includes it.
  3. Clean up stale unit references (user records, external integrations) after deleting or disabling units.

Example fix

// before
await runWithUnitCheck({ businessUnit: unitId, userId }); // throws error-unit-not-found

// after - verify the unit is visible to this user before calling
const unitsFromUser = await getUnitsFromUser(userId);
const unit = await LivechatUnit.findOneById(unitId, { projection: { _id: 1 } }, { unitsFromUser });
if (!unit) throw new Meteor.Error('error-unit-not-found', `Unit ${unitId} missing, inactive, or not assigned to user`);
await runWithUnitCheck({ businessUnit: unitId, userId });
Defensive patterns

Strategy: validation

Validate before calling

const unitsFromUser = await getUnitsFromUser(userId);
const unit = await LivechatUnit.findOneById(businessUnit, { projections: { _id: 1 } }, { unitsFromUser });
if (!unit) {
	// unit missing, inactive, or outside the user's membership; do not proceed with checkUnitsFromUser
}

Try / catch

try {
	await runWithUnitCheck({ businessUnit, userId });
} catch (e: any) {
	if (e?.error === 'error-unit-not-found') {
		throw new Meteor.Error('error-unit-not-found', `Unit ${businessUnit} is missing, inactive, or not assigned to this user`);
	}
	throw e;
}

Prevention

When it happens

Trigger: Any flow routed through checkUnitsFromUser with a businessUnit param that is deleted or disabled, or a valid unit the user has no department membership in - getUnitsFromUser returns the allowed set and findOneById is constrained to it, so both cases produce the same miss.

Common situations: A unit was deleted or disabled during a reorganization but users/integrations still reference its id; the user was removed from the unit's departments so the unit drops out of unitsFromUser; unit ids copied between environments (staging vs production) where the unit does not exist.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at apps/meteor/ee/server/lib/omnichannel/unit.ts:15

import { LivechatUnit } from '@rocket.chat/models';
import { getUnitsFromUser } from '@rocket.chat/omni-core-ee';
import { Meteor } from 'meteor/meteor';

import type { CheckUnitsFromUser } from '../../../../server/api/v1/omnichannel/lib/livechat';
import { checkUnitsFromUser } from '../../../../server/api/v1/omnichannel/lib/livechat';

checkUnitsFromUser.patch(async (_next, { businessUnit, userId }: CheckUnitsFromUser) => {
	if (!businessUnit) {
		return;
	}
	const unitsFromUser = await getUnitsFromUser(userId);
	const unit = await LivechatUnit.findOneById(businessUnit, { projection: { _id: 1 } }, { unitsFromUser });
	if (!unit) {
		throw new Meteor.Error('error-unit-not-found', `Error! No Active Business Unit found with id: ${businessUnit}`);
	}
});

View on GitHub (pinned to b2c16d5842)