RocketChat/Rocket.Chat · error · Error

error-invalid-priority

error-invalid-priority

Error message

error-invalid-priority

What it means

In updateRoomPriority (POST livechat/room/:rid/priority), after the room is found the requested priorityId is resolved with LivechatPriority.findOneById; a miss throws error-invalid-priority. Nothing is written when this fires, so room and inquiry stay consistent.

Source

Thrown at apps/meteor/ee/server/api/v1/omnichannel/lib/priorities.ts:75

		throw Error('error-unable-to-update-priority');
	}

	return createdResult;
}

export const updateRoomPriority = async (
	rid: string,
	user: Required<Pick<IUser, '_id' | 'username' | 'name'>>,
	priorityId: string,
): Promise<void> => {
	const room = await LivechatRooms.findOneById(rid);
	if (!room) {
		throw new Error('error-room-does-not-exist');
	}

	const priority = await LivechatPriority.findOneById(priorityId);
	if (!priority) {
		throw new Error('error-invalid-priority');
	}

	await Promise.all([
		LivechatRooms.setPriorityByRoomId(rid, priority),
		LivechatInquiry.setPriorityForRoom(rid, priority),
		addPriorityChangeHistoryToRoom(room._id, user, priority),
	]);

	void notifyOnRoomChanged({ ...room, priorityId: priority._id, priorityWeight: priority.sortItem }, 'updated');
	void notifyOnLivechatInquiryChangedByRoom(rid, 'updated');
};

export const removePriorityFromRoom = async (rid: string, user: Required<Pick<IUser, '_id' | 'username' | 'name'>>): Promise<void> => {
	const room = await LivechatRooms.findOneById<Omit<IOmnichannelRoom, 'priorityId' | 'priorityWeight'>>(rid, {
		projection: { priorityId: 0, priorityWeight: 0 },
	});
	if (!room) {
		throw new Error('error-room-does-not-exist');

View on GitHub (pinned to b2c16d5842)

Solutions

  1. GET /api/v1/livechat/priorities and use the exact _id field of the priority you want.
  2. Re-fetch the list immediately before assigning if priorities may have been edited or reset concurrently.
  3. If the priority was deleted, recreate it (or run priorities.reset to restore defaults) and retry with the new _id.

Example fix

// before
await api.post(`/v1/livechat/room/${rid}/priority`, { priorityId: 'Urgent' }); // name, not _id

// after
const { priorities } = await api.get('/v1/livechat/priorities', { params: { count: 0 } });
const urgent = priorities.find((p) => p.name === 'Urgent');
if (urgent) await api.post(`/v1/livechat/room/${rid}/priority`, { priorityId: urgent._id });
Defensive patterns

Strategy: validation

Validate before calling

const { priorities } = await api.get('/v1/livechat/priorities', { params: { count: 0 } });
const target = priorities.find((p) => p._id === priorityId);
if (!target) throw new Error(`Priority ${priorityId} not found; refusing to assign`);
await api.post(`/v1/livechat/room/${rid}/priority`, { priorityId: target._id });

Try / catch

try {
  await api.post(`/v1/livechat/room/${rid}/priority`, { priorityId });
} catch (e) {
  if (e?.response?.data?.errorType === 'error-invalid-priority') {
    // refresh the priorities list and re-select a valid _id
  } else throw e;
}

Prevention

When it happens

Trigger: POST /api/v1/livechat/room/<rid>/priority with a priorityId that is not the _id of a LivechatPriority document: a hand-typed id, the priority's display name or i18n key instead of its _id, or a priority an admin deleted.

Common situations: Using the priority name ('Urgent') instead of its _id; referencing a priority deleted while a client tab still had it selected; ids invalidated after priorities were reset to defaults via livechat/priorities.reset.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/829cf1d55257a90c. Report an issue: GitHub.