RocketChat/Rocket.Chat · error · Error
error-contact-not-found
error-contact-not-found
Error message
error-contact-not-found
What it means
getContactHistory resolves the contact with findOneEnabledById (projecting only _id) before querying its chat history, and throws Error('error-contact-not-found') when the id matches no enabled contact. Deleted and disabled contacts therefore have no retrievable history through this path.
Source
Thrown at apps/meteor/server/lib/omnichannel/contacts/getContactHistory.ts:38
}: {
contactId: string;
options?: FindOptions<IOmnichannelRoom>;
extraParams?: Record<string, any>;
}): Promise<FindPaginated<FindCursor<IOmnichannelRoom>>> =>
LivechatRooms.findClosedRoomsByContactPaginated({
contactId,
options,
}),
);
export const getContactHistory = makeFunction(
async (params: GetContactHistoryParams): Promise<PaginatedResult<{ history: VisitorSearchChatsResult[] }>> => {
const { contactId, count, offset, sort } = params;
const contact = await LivechatContacts.findOneEnabledById<Pick<ILivechatContact, '_id'>>(contactId, { projection: { _id: 1 } });
if (!contact) {
throw new Error('error-contact-not-found');
}
const options: FindOptions<IOmnichannelRoom> = {
sort: sort || { closedAt: -1 },
skip: offset,
limit: count,
projection: {
fname: 1,
ts: 1,
v: 1,
msgs: 1,
servedBy: 1,
closedAt: 1,
closedBy: 1,
closer: 1,
tags: 1,
source: 1,
lastMessage: 1,View on GitHub (pinned to b2c16d5842)
Solutions
- Verify the contact exists and is enabled before requesting its history
- If the contact was disabled, surface 'history unavailable' rather than retrying
- Refresh contact lists after disable/delete operations so stale ids are not queried
Defensive patterns
Strategy: validation
Validate before calling
import { LivechatContacts } from '@rocket.chat/models';
const contact = await LivechatContacts.findOneEnabledById(contactId, { projection: { _id: 1 } });
if (!contact) {
// skip the history call: contact deleted or disabled - respond 'history unavailable'
} Try / catch
try {
const history = await getContactHistory({ contactId, count, offset });
} catch (err: any) {
if (err?.message === 'error-contact-not-found') return respondNotFound(contactId);
throw err;
} Prevention
- Refresh contact listings after disable/delete operations so stale ids are not queried
- Gate history views on the contact's enabled state
- Handle 'not found' as a normal, non-retryable outcome
When it happens
Trigger: Calling the contact-history endpoint/method for a deleted contact, a contact already disabled (e.g. after a privacy wipe), or a plain invalid id.
Common situations: UI listings showing stale contacts after a concurrent disable; pagination cursors surviving past deletion; token/id confusion common to the other contact endpoints.
Related errors
- error-contact-not-found
- error-visitor-not-found
- error-invalid-contact
- error-contact-not-found
- error-contact-not-found
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/8813db92b60e9e5d.
Report an issue: GitHub.