RocketChat/Rocket.Chat · warning · Error

Invalid type

Error message

Invalid type

What it means

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.

Source

Thrown at apps/meteor/server/api/v1/omnichannel/users.ts:71

				);
			}
			if (this.urlParams.type === 'manager') {
				if (!(await hasAtLeastOnePermissionAsync(this.user, ['view-livechat-manager']))) {
					return API.v1.forbidden();
				}

				return API.v1.success(
					await findManagers({
						text,
						pagination: {
							offset,
							count,
							sort,
						},
					}),
				);
			}
			throw new Error('Invalid type');
		},
		async post() {
			if (this.urlParams.type === 'agent') {
				const user = await addAgent(this.bodyParams.username);
				if (user) {
					return API.v1.success({ user });
				}
			} else if (this.urlParams.type === 'manager') {
				const user = await addManager(this.bodyParams.username);
				if (user) {
					return API.v1.success({ user });
				}
			} else {
				throw new Error('Invalid type');
			}

			return API.v1.failure();
		},

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Use only the literal values 'agent' or 'manager' for the :type segment.
  2. Lowercase the value before building the URL to avoid casing issues.
  3. Add a client-side enum/union guard so invalid values never reach the network call.

Example fix

null
Defensive patterns

Strategy: type-guard

Validate before calling

const TYPE = ['agent', 'manager'];
if (!TYPE.includes(type.toLowerCase())) throw new Error('bad type');
await fetch(`/api/v1/v1/livechat/users/${type}`);

Type guard

function isLivechatUserType(t: string): t is 'agent' | 'manager' {
  return t === 'agent' || t === 'manager';
}

Try / catch

null

Prevention

When it happens

Trigger: 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'.

Common situations: Client hardcodes the type string and a refactor changes the vocabulary; URL builder concatenates an undefined value; integration sends a localized role name.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/242ea89d6833521f. Report an issue: GitHub.