{"record":{"id":"ac30af424b0dd9f8","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-ac30af","errorCode":"error-invalid-room","errorMessage":"Invalid room","messagePattern":"Invalid room","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/im.ts","lineNumber":985,"sourceCode":"\t\t200: ajv.compile<void>({\n\t\t\ttype: 'object',\n\t\t\tproperties: {\n\t\t\t\tsuccess: { type: 'boolean', enum: [true] },\n\t\t\t},\n\t\t\trequired: ['success'],\n\t\t\tadditionalProperties: false,\n\t\t}),\n\t},\n} as const;\n\nconst dmBlockUserAction = <Path extends string>(_path: Path): TypedAction<typeof dmBlockUserEndpointsProps, Path> =>\n\tasync function action() {\n\t\tconst { roomId, block } = this.bodyParams;\n\t\tconst { room } = await findDirectMessageRoom({ roomId }, this.userId);\n\n\t\tconst blocked = room.uids?.find((uid) => uid !== this.userId);\n\t\tif (!blocked) {\n\t\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'im.blockUser' });\n\t\t}\n\n\t\tif (block) {\n\t\t\tawait blockUserMethod(this.userId, { rid: room._id, blocked });\n\t\t} else {\n\t\t\tawait unblockUserMethod(this.userId, { rid: room._id, blocked });\n\t\t}\n\n\t\treturn API.v1.success();\n\t};\n\nconst dmEndpoints = API.v1\n\t.post('im.delete', dmDeleteEndpointsProps, dmDeleteAction('im.delete'))\n\t.post('dm.delete', dmDeleteEndpointsProps, dmDeleteAction('dm.delete'))\n\t.post('dm.close', dmCloseEndpointsProps, dmCloseAction('dm.close'))\n\t.post('im.close', dmCloseEndpointsProps, dmCloseAction('im.close'))\n\t.post('dm.create', dmCreateEndpointsProps, dmCreateAction('dm.create'))\n\t.post('im.create', dmCreateEndpointsProps, dmCreateAction('im.create'))","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/im.ts#L967-L1003","documentation":"dmBlockUserAction resolves the DM, then computes blocked = room.uids?.find(uid => uid !== this.userId). If there is no 'other' user it throws error-invalid-room with method 'im.blockUser'. This fires for self-DMs (only one uid), DMs whose uids array is empty/missing, or odd DM states.","triggerScenarios":"POST /api/v1/im.blockUser on a DM that has no counterpart user — e.g. a self-message room, a DM whose other participant was removed leaving a single uid, or a malformed room document without uids.","commonSituations":"Trying to block yourself (the DM with yourself); the other user was deleted and the room collapsed to one uid; legacy room documents missing the uids field.","solutions":["Confirm the DM actually has a second participant before calling block.","Do not call block on a self-DM.","If the counterpart was removed, re-create the DM (im.create) before blocking."],"exampleFix":"// before\nPOST /api/v1/im.blockUser { roomId: <self-dm> } // only one uid\n\n// after\nconst room = await GET /api/v1/im.rooms.info?roomId=<rid>;\nif (room.uids.length === 2) {\n  await POST /api/v1/im.blockUser { roomId, block: true };\n}","handlingStrategy":"validation","validationCode":"// Verify the DM has a counterpart user before blocking\nconst room = (await api.get('/api/v1/rooms.info', { params: { roomId } })).data.room;\nconst others = (room.uids || []).filter(uid => uid !== CURRENT_USER_ID);\nif (others.length !== 1) {\n  throw new Error('DM has no blockable counterpart user');\n}","typeGuard":"function isBlockableDm(room: unknown, me: string): room is { _id: string; uids: [string, string] } {\n  const uids = (room as any)?.uids;\n  return Array.isArray(uids) && uids.filter((u: string) => u !== me).length === 1;\n}","tryCatchPattern":"try {\n  await api.post('/api/v1/im.blockUser', { roomId, block: true });\n} catch (e) {\n  if (e.response?.data?.error === 'error-invalid-room') {\n    // self-DM or no counterpart — skip blocking\n  } else throw e;\n}","preventionTips":["Never call block on a self-DM.","Check room.uids has exactly one non-caller uid first.","Re-create DMs whose counterpart user was deleted before blocking."],"tags":["direct-message","block","validation","api"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}