diff --git a/.changeset/fine-olives-nail.md b/.changeset/fine-olives-nail.md
new file mode 100644
index 0000000000000..e5bda9afeb842
--- /dev/null
+++ b/.changeset/fine-olives-nail.md
@@ -0,0 +1,5 @@
+---
+'@rocket.chat/meteor': patch
+---
+
+Fixes the two-factor email "Resend" toast showing `[object Object]` when the server refuses the request, for example after too many resends in one minute. The REST rate limit message also no longer starts with an extra "Error,".
diff --git a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.spec.tsx b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.spec.tsx
index 0aeeb7fa106fb..ceb5c6e104d7b 100644
--- a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.spec.tsx
+++ b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.spec.tsx
@@ -4,6 +4,10 @@ import userEvent from '@testing-library/user-event';
import TwoFactorEmailModal from './TwoFactorEmailModal';
+jest.mock('../../../lib/i18n', () => ({
+ t: (key: string) => key,
+}));
+
it.each(['error-challenge-expired', 'error-challenge-not-found'])(
'tells the user to log in again when resending with a challenge that is gone (%s)',
async (errorType) => {
@@ -38,3 +42,25 @@ it('tells the user a new code is sent at most once a minute when resending succe
await waitFor(() => expect(dispatch).toHaveBeenCalledWith({ type: 'success', message: 'One code each minute' }));
});
+
+it('shows the server reason when resending is rate limited', async () => {
+ const dispatch = jest.fn();
+ const reason =
+ 'Too many requests. Please slow down. You must wait 42 seconds before trying this endpoint again. [error-too-many-requests]';
+ const wrapper = mockAppRoot()
+ .withTranslations('en', 'core', {
+ 'error-email-send-failed': 'Error trying to send email: {{message}}',
+ 'Cloud_resend_email': 'Resend email',
+ })
+ .withEndpoint('POST', '/v1/users.2fa.sendEmailCode', () => {
+ throw Object.assign(new Error(), { success: false, error: reason });
+ })
+ .withToastMessageDispatch(dispatch)
+ .build();
+
+ render(, { wrapper });
+
+ await userEvent.click(screen.getByRole('button', { name: 'Resend email' }));
+
+ await waitFor(() => expect(dispatch).toHaveBeenCalledWith({ type: 'error', message: `Error trying to send email: ${reason}` }));
+});
diff --git a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx
index 30ea40905e492..fbfacac194893 100644
--- a/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx
+++ b/apps/meteor/client/components/TwoFactorModal/TwoFactorEmailModal.tsx
@@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next';
import type { OnConfirm } from './TwoFactorModal';
import { Method } from './TwoFactorModal';
+import { getErrorMessage } from '../../lib/errorHandling';
export type TwoFactorEmailModalProps = {
onConfirm: OnConfirm;
@@ -62,7 +63,9 @@ const TwoFactorEmailModal = ({ onConfirm, onClose, invalidAttempt, emailOrUserna
const expired = errorType === 'error-challenge-expired' || errorType === 'error-challenge-not-found';
dispatchToastMessage({
type: 'error',
- message: expired ? t('Two-factor_authentication_expired') : t('error-email-send-failed', { message: error }),
+ message: expired
+ ? t('Two-factor_authentication_expired')
+ : t('error-email-send-failed', { message: getErrorMessage(error, 'Something_went_wrong') }),
});
}
};
diff --git a/apps/meteor/server/api/ApiClass.ts b/apps/meteor/server/api/ApiClass.ts
index 19cd0eaa1bf18..d49d745ad78d3 100644
--- a/apps/meteor/server/api/ApiClass.ts
+++ b/apps/meteor/server/api/ApiClass.ts
@@ -458,7 +458,7 @@ export class APIClass