{"record":{"id":"d2c523610c34d9ac","repo":"RocketChat/Rocket.Chat","slug":"invalid-room","errorCode":null,"errorMessage":"invalid-room","messagePattern":"invalid-room","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/agent.ts","lineNumber":33,"sourceCode":"import { findRoom, findGuest, findAgent, findOpenRoom } from './lib/livechat';\nimport { hasPermissionAsync } from '../../../lib/authorization/hasPermission';\nimport { hasRoleAsync } from '../../../lib/authorization/hasRole';\nimport { RoutingManager } from '../../../lib/omnichannel/RoutingManager';\nimport { getRequiredDepartment } from '../../../lib/omnichannel/departmentsLib';\nimport { saveAgentInfo } from '../../../lib/omnichannel/omni-users';\nimport { setUserStatusLivechat, allowAgentChangeServiceStatus } from '../../../lib/omnichannel/utils';\nimport type { ExtractRoutesFromAPI } from '../../ApiClass';\n\nAPI.v1.addRoute('livechat/agent.info/:rid/:token', {\n\tasync get() {\n\t\tconst visitor = await findGuest(this.urlParams.token);\n\t\tif (!visitor) {\n\t\t\tthrow new Error('invalid-token');\n\t\t}\n\n\t\tconst room = await findRoom(this.urlParams.token, this.urlParams.rid);\n\t\tif (!room) {\n\t\t\tthrow new Error('invalid-room');\n\t\t}\n\n\t\tconst agent = room?.servedBy && (await findAgent(room.servedBy._id));\n\t\tif (!agent) {\n\t\t\tthrow new Error('invalid-agent');\n\t\t}\n\n\t\treturn API.v1.success({ agent });\n\t},\n});\n\nAPI.v1.addRoute(\n\t'livechat/agent.next/:token',\n\t{ validateParams: isGETAgentNextToken },\n\t{\n\t\tasync get() {\n\t\t\tconst { token } = this.urlParams;\n\t\t\tconst room = await findOpenRoom(token, undefined, this.userId);","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/agent.ts#L15-L51","documentation":"Thrown by GET /api/v1/livechat/agent.info/:rid/:token when findRoom(token, rid) returns null. findRoom queries LivechatRooms by both the visitor token and the room ID — so this error means either the room ID is wrong, the room does not belong to this visitor, or the room no longer exists.","triggerScenarios":"Calling agent.info with a valid visitor token but a room ID that doesn't exist or isn't associated with that visitor's token. findRoom uses findOneByIdAndVisitorToken(rid, token), so both must match.","commonSituations":"Room was closed and removed; room ID from a different conversation; visitor token doesn't own the specified room; room ID typo or copy error.","solutions":["Verify the room ID is correct and belongs to the visitor identified by the token.","Check if the room still exists in LivechatRooms collection.","If the room was closed, start a new livechat session to get a new room ID."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the room exists and belongs to the visitor before calling agent.info\n// Use the livechat room endpoint\nasync function verifyRoom(baseUrl, token, rid) {\n  const res = await fetch(`${baseUrl}/api/v1/livechat/room/${rid}?token=${token}`);\n  return res.ok;\n}\n\nif (!(await verifyRoom(baseUrl, token, rid))) {\n  throw new Error('Room not found or does not belong to this visitor');\n}","typeGuard":"function isValidRoomId(rid: unknown): rid is string {\n  return typeof rid === 'string' && /^[A-Za-z0-9]{17}$/.test(rid);\n}","tryCatchPattern":"try {\n  await getAgentInfo(rid, token);\n} catch (e) {\n  if (e.message === 'invalid-room') {\n    console.error('Room not found for this visitor. Start a new livechat session.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Verify the room ID and visitor token are from the same livechat session.","Handle room closure gracefully by detecting invalid-room and prompting the user to start a new chat."],"tags":["omnichannel","livechat","room","visitor"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}