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
- 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.
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
- 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.
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
- error-invalid-user
- Creating normal users is currently not supported
- User not provided
- Invalid user id
- error-invalid-sla
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/242ea89d6833521f.
Report an issue: GitHub.