{"record":{"id":"62554309a7a95854","repo":"RocketChat/Rocket.Chat","slug":"error-contact-not-found-625543","errorCode":null,"errorMessage":"error-contact-not-found","messagePattern":"error-contact-not-found","errorType":"exception","errorClass":"ContactNotFoundError","httpStatus":null,"severity":"warning","filePath":"apps/meteor/client/views/omnichannel/components/outboundMessage/components/OutboundMessageWizard/forms/RecipientForm/RecipientForm.tsx","lineNumber":85,"sourceCode":"\tconst getContact = useEndpoint('GET', '/v1/omnichannel/contacts.get');\n\tconst getProvider = useEndpoint('GET', '/v1/omnichannel/outbound/providers/:id/metadata', { id: providerId });\n\n\tconst customActions = useMemo(() => renderActions?.({ isSubmitting }), [isSubmitting, renderActions]);\n\n\tconst {\n\t\tdata: contact,\n\t\tisError: isErrorContact,\n\t\tisSuccess: isSuccessContact,\n\t\tisFetching: isFetchingContact,\n\t\trefetch: refetchContact,\n\t} = useQuery({\n\t\tqueryKey: omnichannelQueryKeys.contact(contactId),\n\t\tqueryFn: async () => {\n\t\t\tconst data = await getContact({ contactId });\n\n\t\t\t// TODO: Can be safely removed once unknown contacts handling is added to the endpoint\n\t\t\tif (data?.contact && data.contact.unknown) {\n\t\t\t\tthrow new ContactNotFoundError();\n\t\t\t}\n\n\t\t\treturn data;\n\t\t},\n\t\tstaleTime: 5 * 60 * 1000,\n\t\tselect: (data) => data?.contact || undefined,\n\t\tenabled: !!contactId,\n\t});\n\n\tconst {\n\t\tdata: provider,\n\t\tisError: isErrorProvider,\n\t\tisSuccess: isSuccessProvider,\n\t\tisFetching: isFetchingProvider,\n\t\trefetch: refetchProvider,\n\t} = useQuery({\n\t\tqueryKey: omnichannelQueryKeys.outboundProviderMetadata(providerId),\n\t\tqueryFn: () => getProvider(),","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/client/views/omnichannel/components/outboundMessage/components/OutboundMessageWizard/forms/RecipientForm/RecipientForm.tsx#L67-L103","documentation":"In the Outbound Message wizard's RecipientForm, the contact is fetched via useQuery on omnichannelQueryKeys.contact(contactId). The queryFn calls getContact({ contactId }) and throws ContactNotFoundError (message 'error-contact-not-found', a FormFetchError subclass) when the returned contact is marked unknown — a stopgap until the endpoint itself handles unknown contacts. It puts the query in an error state so the form can validate the contact field.","triggerScenarios":"Opening the outbound-message wizard with a contactId whose contact record has unknown: true (visitor not yet a registered contact), or a contactId that resolves to no usable contact object.","commonSituations":"Starting an outbound conversation from a visitor/lead that never became a full contact; stale contactId passed from a previous session; records created by integrations with unknown flag set.","solutions":["Convert the unknown visitor into a registered contact first (Contacts UI or POST /omnichannel/contact), then reopen the wizard.","If the contact was deleted or merged, re-select the recipient to obtain a fresh contactId.","Code-level: key the form off isErrorContact to prompt contact creation instead of submitting."],"exampleFix":"// before\nif (data?.contact && data.contact.unknown) {\n  throw new ContactNotFoundError();\n}\n\n// caller-side: block step advance while contact query is in error\nif (isErrorContact) {\n  validateContactField(true); // show field error, do not proceed\n  return;\n}","handlingStrategy":"validation","validationCode":"const { contact } = await getContact({ contactId });\nif (!contact || contact.unknown) {\n  // convert/register the contact before opening the outbound wizard\n}","typeGuard":"const isUsableContact = (c: IContact | undefined): c is IContact =>\n  Boolean(c && !c.unknown && typeof c._id === 'string');","tryCatchPattern":null,"preventionTips":["Convert unknown visitors to contacts before outbound messaging.","Gate wizard entry on a resolved, non-unknown contact.","Handle isErrorContact by prompting re-selection."],"tags":["rocket-chat","omnichannel","outbound-message","react-query"],"backgroundTag":"entity-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}