{"record":{"id":"242ea89d6833521f","repo":"RocketChat/Rocket.Chat","slug":"invalid-type-242ea8","errorCode":null,"errorMessage":"Invalid type","messagePattern":"Invalid type","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"warning","filePath":"apps/meteor/server/api/v1/omnichannel/users.ts","lineNumber":71,"sourceCode":"\t\t\t\t);\n\t\t\t}\n\t\t\tif (this.urlParams.type === 'manager') {\n\t\t\t\tif (!(await hasAtLeastOnePermissionAsync(this.user, ['view-livechat-manager']))) {\n\t\t\t\t\treturn API.v1.forbidden();\n\t\t\t\t}\n\n\t\t\t\treturn API.v1.success(\n\t\t\t\t\tawait findManagers({\n\t\t\t\t\t\ttext,\n\t\t\t\t\t\tpagination: {\n\t\t\t\t\t\t\toffset,\n\t\t\t\t\t\t\tcount,\n\t\t\t\t\t\t\tsort,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error('Invalid type');\n\t\t},\n\t\tasync post() {\n\t\t\tif (this.urlParams.type === 'agent') {\n\t\t\t\tconst user = await addAgent(this.bodyParams.username);\n\t\t\t\tif (user) {\n\t\t\t\t\treturn API.v1.success({ user });\n\t\t\t\t}\n\t\t\t} else if (this.urlParams.type === 'manager') {\n\t\t\t\tconst user = await addManager(this.bodyParams.username);\n\t\t\t\tif (user) {\n\t\t\t\t\treturn API.v1.success({ user });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error('Invalid type');\n\t\t\t}\n\n\t\t\treturn API.v1.failure();\n\t\t},","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/users.ts#L53-L89","documentation":"Thrown in the GET handler of livechat/users/:type when the :type URL segment is neither 'agent' nor 'manager'. The route does not declare a pattern constraint on :type, so any other string (or a typo) falls through all branches and reaches the unconditional throw at the end of the get() body.","triggerScenarios":"GET /api/v1/v1/livechat/users/foo where foo is not 'agent' or 'manager'; an empty segment due to a double-slash URL; a casing mismatch like 'Agent'.","commonSituations":"Client hardcodes the type string and a refactor changes the vocabulary; URL builder concatenates an undefined value; integration sends a localized role name.","solutions":["Use only the literal values 'agent' or 'manager' for the :type segment.","Lowercase the value before building the URL to avoid casing issues.","Add a client-side enum/union guard so invalid values never reach the network call."],"exampleFix":"null","handlingStrategy":"type-guard","validationCode":"const TYPE = ['agent', 'manager'];\nif (!TYPE.includes(type.toLowerCase())) throw new Error('bad type');\nawait fetch(`/api/v1/v1/livechat/users/${type}`);","typeGuard":"function isLivechatUserType(t: string): t is 'agent' | 'manager' {\n  return t === 'agent' || t === 'manager';\n}","tryCatchPattern":"null","preventionTips":["Centralize the allowed type list in a shared constant.","Lowercase user input before building the URL.","Add a client-side union type to catch drift at compile time."],"tags":["omnichannel","users","validation","url-param"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}