Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Unhandled promise rejection: how to find and fix it

PRF-118Medium impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

A promise is JavaScript's way of saying 'this result will arrive later'. It ends in success (resolved) or failure (rejected). If it is rejected and nothing handles the failure, the browser raises an unhandled promise rejection and prints Uncaught (in promise) in the console.

Common sources on marketing pages: a fetch() to your form endpoint that returns a network error, an await without try/catch, a third-party widget (chat, booking, consent) that throws inside an async callback, or JSON.parse failing on an HTML error page returned by an API.

A typical unhandled rejectionjavascript
form.addEventListener('submit', async (e) => {
  e.preventDefault();
  // If this request fails or returns invalid JSON, the promise rejects
  // and nothing catches it. The visitor sees no change.
  const res = await fetch('/api/lead', { method: 'POST', body: new FormData(form) });
  const data = await res.json();
  window.location.href = '/thank-you';
});

Why it costs you leads or sales

The page does not crash, so the problem is easy to miss. But the code after the failed await never runs. That can mean the lead is not saved, the redirect to the thank-you page never happens, or the conversion tag that fires on that page never loads. The visitor sees nothing happen, clicks again or leaves.

Where a rejection breaks a lead form
  1. Visitor submits formClick handler runs
  2. fetch() to APIRequest fails or returns bad JSON, promise rejects
  3. Redirect to thank-youNever reached
  4. Conversion tagNever fires
  5. Lead in CRMNever created

The failed request is not caught, so every later step is skipped.

How to check if your site has it

Find unhandled rejections yourself
  1. Open DevTools on the funnel page

    In Chrome press F12 (Cmd+Option+I on Mac) and open the Console tab. Tick 'Preserve log' so messages survive navigation.

  2. Walk the journey

    Load the page, fill the form, submit, and continue through each step. Look for red lines starting with 'Uncaught (in promise)'.

  3. Check the Network tab

    Find the request that ran just before the error. A failed status (4xx, 5xx, blocked, CORS) or an HTML response where JSON was expected is the usual cause.

  4. Log them globally

    Paste the listener below in the console, then repeat the journey to see every rejection with its reason.

  5. Test with problems

    In the Network tab set throttling to Offline or block the API URL, then submit. If nothing happens on screen, the failure is not handled.

Log every unhandled rejectionjavascript
window.addEventListener('unhandledrejection', (event) => {
  console.warn('Unhandled rejection:', event.reason);
});

How to fix it

The fix is the same everywhere: handle the failure where the promise is made, and give the visitor a result. Where you do this depends on who owns the code.

Handled version of the form codejavascript
form.addEventListener('submit', async (e) => {
  e.preventDefault();
  const button = form.querySelector('[type="submit"]');
  button.disabled = true;
  try {
    const res = await fetch('/api/lead', { method: 'POST', body: new FormData(form) });
    if (!res.ok) throw new Error('Request failed: ' + res.status);
    await res.json();
    window.location.href = '/thank-you';
  } catch (err) {
    console.error(err);
    document.querySelector('#form-error').textContent =
      'Sorry, we could not send your details. Please try again.';
    button.disabled = false;
  }
});
Fix by platform
  1. Wrap awaits in try/catch

    Or add .catch() to promise chains. Check res.ok before parsing JSON.

  2. Show an error message

    Tell the visitor what happened and re-enable the submit button.

  3. Add a global listener

    Use window.addEventListener('unhandledrejection', ...) to send errors to your error tracker.

How to confirm it's fixed

Confirmation checks
  • Console shows no 'Uncaught (in promise)' while you complete the full journey
  • With the API blocked or the network offline, the visitor sees a clear error and the button works again
  • With the API working, the redirect and thank-you page load as before
  • Conversion tags fire on the thank-you page (check in Network or the platform's debug view)
  • The test lead arrives in the inbox and CRM

How to prevent it happening again

Prevention habits
  • Make try/catch or .catch() part of code review for any fetch or await
  • Check res.ok before calling res.json()
  • Add a global unhandledrejection listener that reports to your error tracking tool
  • Re-test the whole funnel after theme, plugin, app or tag changes
  • Run an automated journey check on a schedule so regressions are noticed quickly

How FunnelGuard handles this

FunnelGuard detects this today. When its robot visitor runs your journeys in Chromium, it captures page errors (the browser's pageerror events), which include unhandled promise rejections raised during the run. The check is tied to the step where the error occurred.

If a step fails, FunnelGuard re-checks from a second region before sending one alert (email, Slack, Teams, WhatsApp, webhook or PagerDuty) with a screenshot and a likely cause. It tells you where the error appeared; fixing the code is still up to you. The Free plan covers 1 site and 2 journeys with daily checks and no card, and paid plans start with a 3-day free trial.

Questions people ask

What does 'Uncaught (in promise)' mean?

It means a promise was rejected and no .catch() or try/catch handled the failure. The browser reports it in the console. The code that depended on that promise did not finish, which can silently break a form or tracking call.

How do I fix an unhandled promise rejection?

Wrap the awaited code in try/catch or add .catch() to the promise chain, check res.ok before parsing a fetch response, and show the visitor a message. Then add a global unhandledrejection listener to catch any that remain.

Why is my form not submitting and the console shows Uncaught (in promise)?

Most likely the request to your form endpoint failed or returned something that is not JSON, so the code after the await never ran. Check the Network tab for the failed request, then add error handling so the visitor gets feedback.

Can an unhandled promise rejection stop my tracking from firing?

Yes, if the rejection happens before the code that sends the tag or redirects to the thank-you page. Anything after the failed await is skipped, so the conversion may never be recorded.

How do I catch all unhandled promise rejections in the browser?

Use window.addEventListener('unhandledrejection', handler). The event's reason property holds the error. Use it to log or report errors, but still fix the source with try/catch where the promise is created.

Is an unhandled promise rejection the same as a JavaScript exception?

Not quite. A normal uncaught exception comes from synchronous code throwing, while a rejection comes from an async operation failing. Both show in the console and both can break a funnel step, but they are caught differently.

Does FunnelGuard detect unhandled promise rejections?

Yes. It captures page errors in Chromium while running your journeys, which include unhandled rejections, and alerts you with a screenshot and likely cause after a second-region re-check.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: pageerror captured in Chromium.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.