RocketChat/Rocket.Chat · warning · FormFetchError
error-department-not-found
Error message
error-department-not-found
What it means
In the Outbound Message wizard's RepliesForm, submit() re-checks the department: if a departmentId was chosen and (after awaiting an in-flight refetch) the department object is still missing, it throws FormFetchError('error-department-not-found'). The catch calls trigger() so react-hook-form surfaces the departmentId field error (registered via the isErrorDepartment effect). The department lives in Omnichannel Departments.
Source
Thrown at apps/meteor/client/views/omnichannel/components/outboundMessage/components/OutboundMessageWizard/forms/RepliesForm/RepliesForm.tsx:100
canAssignSelfOnlyAgent,
canAssignAnyAgent,
});
useEffect(() => {
isErrorDepartment && trigger('departmentId');
return () => clearErrors('departmentId');
}, [clearErrors, isErrorDepartment, trigger]);
const submit = useStableCallback(async ({ agentId, departmentId }: RepliesFormData) => {
try {
const agent = agents?.find((agent) => agent.agentId === agentId);
// Wait if department or agent is still being fetched in background
const updatedDepartment =
departmentId && isFetchingDepartment ? await refetchDepartment().then((r) => r.data?.department) : department;
if (departmentId && !updatedDepartment) {
throw new FormFetchError('error-department-not-found');
}
if (agentId && !agent) {
throw new FormFetchError('error-agent-not-found');
}
onSubmit({ departmentId, department: updatedDepartment, agentId, agent });
} catch (error) {
if (error instanceof FormFetchError) {
trigger();
return;
}
dispatchToastMessage({ type: 'error', message: t('Something_went_wrong') });
}
});
return (View on GitHub (pinned to b2c16d5842)
Solutions
- Verify the department still exists in Administration > Omnichannel > Departments; re-select it in the form.
- Disable submit while the department query is fetching (isFetchingDepartment).
- Clear stale departmentId from saved wizard state when its lookup errors.
Example fix
// before
if (departmentId && !updatedDepartment) {
throw new FormFetchError('error-department-not-found');
}
// after: block submit until department resolves
const canSubmit = !isFetchingDepartment && !(departmentId && !department);
<ActionButton disabled={!canSubmit} onClick={submit} /> Defensive patterns
Strategy: validation
Validate before calling
const canSubmit = !isFetchingDepartment && !(departmentId && !department); // re-select department when its lookup errors
Type guard
const hasDepartment = (d: IDepartment | undefined | null): d is IDepartment => Boolean(d?._id);
Prevention
- Clear stale department selections when departments change.
- Verify the department exists before submitting wizard steps.
- Disable submit while the department refetch is in flight.
When it happens
Trigger: Advancing the replies step with a selected department whose lookup (GET /omnichannel/department/:id) returned nothing — deleted department, empty refetch result, or query still unresolved at submit time.
Common situations: Department removed by an admin while the wizard was open; departmentId persisted from a draft whose department no longer exists; race between slow fetch and submit.
Related errors
- error-contact-not-found
- error-provider-not-found
- error-agent-not-found
- error-forwarding-department-target-not-allowed
- error-not-allowed
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/7d92d55cc4358719.
Report an issue: GitHub.