{"record":{"id":"4afe020f1f633167","repo":"RocketChat/Rocket.Chat","slug":"invalid-room-4afe02","errorCode":null,"errorMessage":"invalid-room","messagePattern":"invalid-room","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/lib/visitors.ts","lineNumber":28,"sourceCode":"\tif (!visitor) {\n\t\tthrow new Error('visitor-not-found');\n\t}\n\n\treturn {\n\t\tvisitor,\n\t};\n}\n\nexport async function findVisitedPages({\n\troomId,\n\tpagination: { offset, count, sort },\n}: {\n\troomId: IRoom['_id'];\n\tpagination: { offset: number; count: number; sort: FindOptions<IMessage>['sort'] };\n}) {\n\tconst room = await LivechatRooms.findOneById(roomId);\n\tif (!room) {\n\t\tthrow new Error('invalid-room');\n\t}\n\tconst { cursor, totalCount } = Messages.findPaginatedByRoomIdAndType(room._id, 'livechat_navigation_history', {\n\t\tsort: sort || { ts: -1 },\n\t\tskip: offset,\n\t\tlimit: count,\n\t});\n\n\tconst [pages, total] = await Promise.all([cursor.toArray(), totalCount]);\n\n\treturn {\n\t\tpages,\n\t\tcount: pages.length,\n\t\toffset,\n\t\ttotal,\n\t};\n}\n\nexport async function findChatHistory({","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/lib/visitors.ts#L10-L46","documentation":"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' }.","triggerScenarios":"Calling findVisitedPages with a roomId that does not exist (typo, deleted room, or passing a message/visitor id by mistake).","commonSituations":"Wrong id type passed; room deleted after the client cached its id; copy-paste of a messageId into the roomId slot.","solutions":["Verify the room exists with LivechatRooms.findOneById(roomId) before calling.","Source roomId only from a known livechat room record."],"exampleFix":"// before\nfindVisitedPages({ roomId: someId, pagination }); // throws invalid-room if missing\n\n// after\nconst room = await LivechatRooms.findOneById(roomId);\nif (!room) throw new Error('room does not exist');\nfindVisitedPages({ roomId: room._id, pagination });","handlingStrategy":"validation","validationCode":"const room = await LivechatRooms.findOneById(roomId, { projection: { _id: 1 } });\nif (!room) throw new Error('room does not exist');\n// safe to call findVisitedPages({ roomId })","typeGuard":"const roomExists = async (id: string) => !!(await LivechatRooms.findOneById(id, { projection: { _id: 1 } }));","tryCatchPattern":"try { await findVisitedPages({ roomId, pagination }); }\ncatch (e) { if (e instanceof Error && e.message === 'invalid-room') { /* 404 / re-fetch roomId */ } else throw e; }","preventionTips":["Source roomId only from a real livechat room record.","Don't confuse messageId/visitorId with roomId."],"tags":["livechat","omnichannel","room","rest-api"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}