{"record":{"id":"a2dcba76572c2b2b","repo":"RocketChat/Rocket.Chat","slug":"the-required-mid-body-param-is-missing","errorCode":"The required \"mid\" body param is missing.","errorMessage":"The required \"mid\" body param is missing.","messagePattern":"The required \"mid\" body param is missing\\.","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/api/v1/chat.ts","lineNumber":481,"sourceCode":"\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t\t200: ajv.compile<void>({\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tsuccess: {\n\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\trequired: ['success'],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t}),\n\t\t\t},\n\t\t},\n\t\tasync function action() {\n\t\t\tconst { mid } = this.bodyParams;\n\n\t\t\tif (!mid) {\n\t\t\t\tthrow new Meteor.Error('The required \"mid\" body param is missing.');\n\t\t\t}\n\n\t\t\tawait followMessage(this.user, { mid });\n\n\t\t\treturn API.v1.success();\n\t\t},\n\t)\n\t.post(\n\t\t'chat.unfollowMessage',\n\t\t{\n\t\t\tauthRequired: true,\n\t\t\tbody: isChatUnfollowMessageLocalProps,\n\t\t\tresponse: {\n\t\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t\t200: ajv.compile<void>({\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tproperties: {","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/chat.ts#L463-L499","documentation":"Thrown by chat.followMessage when this.bodyParams.mid is falsy. Notably the thrown value is a Meteor.Error whose code IS the full message string ('The required \"mid\" body param is missing.') rather than a stable error code - so client matching must compare against the literal string, not a symbolic code. The body is also parsed through isChatFollowMessageLocalProps before this, so reaching this throw suggests the schema allowed a missing mid.","triggerScenarios":"POST chat.followMessage with no mid in the body, an empty string mid, or a body the schema validator passed through without binding mid.","commonSituations":"Client omitting mid; form field named differently (e.g., messageId instead of mid); AJV schema for the body not requiring mid, letting the action reach this manual guard.","solutions":["Always include mid in the request body for chat.followMessage.","Tighten the body schema (isChatFollowMessageLocalProps) to require mid, so the framework returns a 400 before the action runs.","Match on the literal message string in the client (there is no symbolic code)."],"exampleFix":"// before\nthrow new Meteor.Error('The required \"mid\" body param is missing.');\n\n// after - stable code + human message\nthrow new Meteor.Error('error-param-required', 'The required \"mid\" body param is missing.');\n\n// and enforce it in the schema so the action never sees a missing mid:\n// const isChatFollowMessageLocalProps = ajv.compile({\n//   type: 'object',\n//   properties: { mid: { type: 'string' } },\n//   required: ['mid'],\n//   additionalProperties: false,\n// });","handlingStrategy":"validation","validationCode":"function requireMid(body) {\n  if (!body || typeof body.mid !== 'string' || body.mid.trim() === '') {\n    throw new Error('The \"mid\" body param is required');\n  }\n  return body.mid;\n}","typeGuard":"function hasValidMid(body) {\n  return Boolean(body) && typeof body.mid === 'string' && body.mid.trim().length > 0;\n}","tryCatchPattern":"try {\n  await api.followMessage({ mid });\n} catch (e) {\n  // No symbolic code - match the literal message\n  if (e.error === 'The required \"mid\" body param is missing.' || /mid.*required/.test(e.message)) {\n    highlightFollowError();\n    return;\n  }\n  throw e;\n}","preventionTips":["Always include mid in the body for chat.followMessage.","Tighten isChatFollowMessageLocalProps to require mid so the framework 400s earlier.","Note this error has no stable code - clients must match the message string."],"tags":["chat","validation","required-param","follow","rest-api"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}