RocketChat/Rocket.Chat · error · Error

invalid-room

Error message

invalid-room

What it means

findVisitedPages (backing GET /api/v1/livechat/visitors.pagesHistory/:roomId) first resolves LivechatRooms.findOneById(roomId); when no room document with that _id exists it throws 'invalid-room' before querying navigation-history messages.

Solutions

  1. Use the rid exactly as returned by the room/message APIs for the same environment.
  2. If the room was deleted, treat visited pages as gone and render an empty history.
  3. Sanity-check the id (24-hex Mongo ObjectId format) before calling to catch truncation/copy errors.
Defensive patterns

Strategy: validation

Validate before calling

const OBJ_ID = /^[0-9a-f]{24}$/i;
if (!OBJ_ID.test(roomId)) throw new TypeError('malformed roomId');
// If in doubt, confirm the room exists first (rooms.info or an equivalent room lookup you already use)
const room = await getRoomById(roomId);
if (!room) return { pages: [], total: 0 }; // deleted room -> no navigation history
return getVisitedPages(roomId, pagination);

Try / catch

try { return await findVisitedPages({ roomId, pagination }); } catch (e) { if (e.message === 'invalid-room') return { pages: [], count: 0, offset: pagination.offset, total: 0 }; throw e; }

Prevention

When it happens

Trigger: Calling pagesHistory with a mistyped rid, a room id from another workspace, or a room whose document was deleted (e.g. by retention/pruning) while its messages or client state lingered.

Common situations: Rid captured from an old chat URL or export; room removed by cleanup jobs; client state referencing a room after the visitor re-registered with a new room.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: 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 b2c16d5842)