RocketChat/Rocket.Chat · error · Error

invalid-room

Error message

invalid-room

What it means

Thrown by findVisitedPages (visitors.ts:19-29) when LivechatRooms.findOneById(roomId) returns null — there is no room with that `_id`. This guard runs before querying the livechat_navigation_history messages for the room. Returns HTTP 400 { success:false, error:'invalid-room' }.

Source

Thrown at apps/meteor/server/api/v1/omnichannel/lib/visitors.ts:28

	if (!visitor) {
		throw new Error('visitor-not-found');
	}

	return {
		visitor,
	};
}

export async function findVisitedPages({
	roomId,
	pagination: { offset, count, sort },
}: {
	roomId: IRoom['_id'];
	pagination: { offset: number; count: number; sort: FindOptions<IMessage>['sort'] };
}) {
	const room = await LivechatRooms.findOneById(roomId);
	if (!room) {
		throw new Error('invalid-room');
	}
	const { cursor, totalCount } = Messages.findPaginatedByRoomIdAndType(room._id, 'livechat_navigation_history', {
		sort: sort || { ts: -1 },
		skip: offset,
		limit: count,
	});

	const [pages, total] = await Promise.all([cursor.toArray(), totalCount]);

	return {
		pages,
		count: pages.length,
		offset,
		total,
	};
}

export async function findChatHistory({

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Verify the room exists with LivechatRooms.findOneById(roomId) before calling.
  2. Source roomId only from a known livechat room record.

Example fix

// before
findVisitedPages({ roomId: someId, pagination }); // throws invalid-room if missing

// after
const room = await LivechatRooms.findOneById(roomId);
if (!room) throw new Error('room does not exist');
findVisitedPages({ roomId: room._id, pagination });
Defensive patterns

Strategy: validation

Validate before calling

const room = await LivechatRooms.findOneById(roomId, { projection: { _id: 1 } });
if (!room) throw new Error('room does not exist');
// safe to call findVisitedPages({ roomId })

Type guard

const roomExists = async (id: string) => !!(await LivechatRooms.findOneById(id, { projection: { _id: 1 } }));

Try / catch

try { await findVisitedPages({ roomId, pagination }); }
catch (e) { if (e instanceof Error && e.message === 'invalid-room') { /* 404 / re-fetch roomId */ } else throw e; }

Prevention

When it happens

Trigger: Calling findVisitedPages with a roomId that does not exist (typo, deleted room, or passing a message/visitor id by mistake).

Common situations: Wrong id type passed; room deleted after the client cached its id; copy-paste of a messageId into the roomId slot.

Related errors


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