RocketChat/Rocket.Chat · error · Error

Default business hour not found

Error message

Default business hour not found

What it means

During onDepartmentDisabled, after unlinking a department from its business hour, the code fetches the workspace's default business hour to close agents' caches for both hours. If findOneDefaultBusinessHour() returns null (no default business-hour record), it throws 'Default business hour not found'.

Source

Thrown at apps/meteor/ee/server/lib/omnichannel/business-hour/Multiple.ts:190

		}

		// Get business hour
		let businessHour = await this.BusinessHourRepository.findOneById(department.businessHourId);
		if (!businessHour) {
			bhLogger.error({
				msg: 'onDepartmentDisabled: business hour not found',
				businessHourId: department.businessHourId,
			});
			return;
		}

		// Unlink business hour from department
		await LivechatDepartment.removeBusinessHourFromDepartmentsByIdsAndBusinessHourId([department._id], businessHour._id);

		// cleanup user's cache for default business hour and this business hour
		const defaultBH = await this.BusinessHourRepository.findOneDefaultBusinessHour();
		if (!defaultBH) {
			throw new Error('Default business hour not found');
		}
		await this.UsersRepository.closeAgentsBusinessHoursByBusinessHourIds([businessHour._id, defaultBH._id]);

		// If i'm the only one, disable the business hour
		const imTheOnlyOne = !(await LivechatDepartment.countByBusinessHourIdExcludingDepartmentId(businessHour._id, department._id));
		if (imTheOnlyOne) {
			bhLogger.warn({
				msg: 'onDepartmentDisabled: department is the only one on business hour, disabling it',
				departmentId: department._id,
				businessHourId: businessHour._id,
			});
			await this.BusinessHourRepository.disableBusinessHour(businessHour._id);

			businessHour = await this.BusinessHourRepository.findOneById(department.businessHourId);
			if (!businessHour) {
				throw new Error(`Business hour ${department.businessHourId} not found`);
			}
		}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Re-create/restore the default business hour record (re-enable business hours in settings so defaults are seeded)
  2. Check the LivechatBusinessHours collection for the document with defaultValue/activeDefault flags
  3. If disabling business hours entirely is intended, disable the feature before removing department links
Defensive patterns

Strategy: try-catch

Validate before calling

const defaultBH = await BusinessHourRepository.findOneDefaultBusinessHour();
if (!defaultBH) {
	// re-seed the default business hour before disabling departments
}
await onDepartmentDisabled(department);

Try / catch

try {
	await onDepartmentDisabled(department);
} catch (err) {
	if (err instanceof Error && err.message === 'Default business hour not found') {
		// data integrity issue: create/restore the default BH record, then retry
	} else {
		throw err;
	}
}

Prevention

When it happens

Trigger: Disabling a department that references a business hour while the instance has no default business-hour document in the database.

Common situations: Fresh or migrated installation where the default BH record was never created; default business hour removed manually from the DB; legacy data missing the default record.

Related errors


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