Skip to content

Conversation

@gabrielmfern
Copy link
Member

@gabrielmfern gabrielmfern commented Oct 15, 2024

Before the response from fetch was, for some reason, throwing an error and falling back to the generic error message when there was a rate limiting. I'm not sure what causes it, but moving the fetch to a server action fixes this temporarily.

To illustrate, if the code is changed to

try {
  const response = await fetch('https://react.email/api/send/test', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      to,
      subject,
      html: markup,
    }),
  });

  if (response.ok) {
    toast.success('Email sent! Check your inbox.');
  } else if (response.status === 429) {
    toast.error('Too many requests. Try again in around 1 minute');
  } else {
    toast.error('Something went wrong. Please try again.');
  }
} catch (exception) {
  console.dir(exception);
  toast.error('Something went wrong. Please try again.');
}

The error message when trying to send more emails than the rate limiting window we have set up allows becomes:

image

And the exception in the console looks like:

TypeError: Failed to fetch
    at onFormSubmit (http://localhost:3000/_next/static/chunks/packages_preview-server_src_components_cfb89c94._.js?id=%255Bproject%255D%252Fpackages%252Fpreview-server%252Fsrc%252Fcomponents%252Fsend.tsx+%255Bapp-client%255D+%2528ecmascript%2529:31:36)
    at onSubmit (http://localhost:3000/_next/static/chunks/packages_preview-server_src_components_cfb89c94._.js?id=%255Bproject%255D%252Fpackages%252Fpreview-server%252Fsrc%252Fcomponents%252Fsend.tsx+%255Bapp-client%255D+%2528ecmascript%2529:97:45)
    at executeDispatch (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:10308:13)
    at runWithFiberInDEV (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:959:74)
    at processDispatchQueue (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:10334:41)
    at http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:10609:13
    at batchedUpdates$1 (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:2247:44)
    at dispatchEventForPluginEventSystem (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:10410:9)
    at dispatchEvent (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:12925:37)
    at dispatchDiscreteEvent (http://localhost:3000/_next/static/chunks/47c98_next_dist_compiled_react-dom_5686b1df._.js:12907:64)

@gabrielmfern gabrielmfern added App: Preview Package: react-email This is the CLI we generally use as just `email` on the temrinal. labels Oct 15, 2024
@gabrielmfern gabrielmfern self-assigned this Oct 15, 2024
@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2024

🦋 Changeset detected

Latest commit: 89d577f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@react-email/preview-server Patch
react-email Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 15, 2024

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
react-email Ready Ready Preview Comment Dec 8, 2025 2:05pm
react-email-demo Ready Ready Preview Comment Dec 8, 2025 2:05pm

@gabrielmfern gabrielmfern force-pushed the feat/error-feedback-for-test-email-sending branch from ecdf85c to 971aa33 Compare November 4, 2024 16:37
@gabrielmfern gabrielmfern force-pushed the canary branch 3 times, most recently from 66c5ab9 to 9f5b6d3 Compare November 8, 2024 16:46
@gabrielmfern gabrielmfern force-pushed the feat/error-feedback-for-test-email-sending branch from 971aa33 to 778a6bb Compare November 21, 2024 15:43
@gabrielmfern gabrielmfern force-pushed the canary branch 2 times, most recently from 4ee4d1d to 0187b0a Compare December 23, 2024 13:28
@gabrielmfern gabrielmfern force-pushed the canary branch 2 times, most recently from bf3f899 to 1748335 Compare January 13, 2025 16:13
@gabrielmfern gabrielmfern force-pushed the feat/error-feedback-for-test-email-sending branch from 353784c to aa45ff7 Compare December 8, 2025 14:01
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 8, 2025

Open in StackBlitz

npm i https://pkg.pr.new/resend/react-email/@react-email/preview-server@1735

commit: 89d577f

@gabrielmfern gabrielmfern changed the title feat(react-email): Proper error feedback for when there is rate limiting feat(preview-server): error feedback for rate limiting Dec 8, 2025
@gabrielmfern gabrielmfern merged commit 3fd1420 into canary Dec 10, 2025
16 of 19 checks passed
@gabrielmfern gabrielmfern deleted the feat/error-feedback-for-test-email-sending branch December 10, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App: Preview Package: react-email This is the CLI we generally use as just `email` on the temrinal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants