Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Sentry: Non-Error promise rejection captured with value in a React app

ErrorNon-Error promise rejection captured with value: Object Not Found Matching Id

Short answer

Sentry raises this event when something that is not an Error object is thrown or used to reject a promise, for example a plain object from an API. Find the rejecting code, wrap the value in a real Error, and keep the object as extra data. Filter what you cannot change with ignoreErrors or beforeSend.

  • Applies to Sentry JavaScript SDK 8 or newer, React 19, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the event in Sentry and read the Additional Data section. The object's contents are in __serialized__, which points at the code that produced it.

    # Sentry > Issue > Additional Data > __serialized__
  2. 2Match what you see, then jump to its fix

    1. 1The event has __serialized__ data and no useful stack traceYour code rejects or throws a plain object or stringFix
    2. 2The object comes from a third-party client or an API wrapperA library rejects with an object you cannot changeFix
    3. 3Events appear for rejections you already handle elsewhereUnhandled rejections are captured automatically and you want controlFix

What does the error look like?

  • Non-Error promise rejection captured with value: Object Not Found Matching Id
  • Non-Error exception (or promise rejection) captured with keys: x, y, z

Cause 1 of 3

Your code rejects or throws a plain object or string

1Check

This event appears when a plain object, not an Error, is thrown, rejected or passed to captureException.

grep -rnE "reject\(|throw \{|throw '" src/ server/

2Fix

Reject and throw Error objects. Keep the original payload on the error so it is still visible.

// before
return Promise.reject({ code: 404, message: 'Object Not Found Matching Id' });
// after
const err = new Error('Object Not Found Matching Id');
err.cause = { code: 404 };
return Promise.reject(err);

3Verify

Trigger the failing path; the new event has a stack trace.

# Reproduce the request, then open the new event in Sentry

Confirmed by docs.sentry.io

Did this fix it?

Cause 2 of 3

A library rejects with an object you cannot change

1Check

If the source is outside your code, you can drop the event on the client before it is sent.

grep -n "Sentry.init" -A8 src/index.js

2Fix

Filter with ignoreErrors (a string matches partially, a regex can be anchored) or return null from beforeSend for events you decide not to send.

Sentry.init({
  dsn: process.env.REACT_APP_SENTRY_DSN,
  ignoreErrors: [/Object Not Found Matching Id/],
});

3Verify

The noisy event no longer arrives.

# Trigger the rejection and check the Sentry issue count

Confirmed by docs.sentry.io

Did this fix it?

Cause 3 of 3

Unhandled rejections are captured automatically and you want control

1Check

The GlobalHandlers integration reports unhandled rejections. Its onunhandledrejection option can be set to false.

grep -rn "GlobalHandlers" src/

2Fix

Turn the option off, then call Sentry.captureException yourself where you want a report.

// In the GlobalHandlers integration options set:
//   onunhandledrejection: false
// then report the rejections you care about yourself:
Sentry.captureException(error);

3Verify

Unhandled rejections stop creating events unless you capture them.

# Trigger a rejection and check Sentry

Confirmed by docs.sentry.io

Did this fix it?

How do I stop it coming back?

  • Always reject and throw Error objects, never plain objects or strings.
  • Normalise API failures into one error class at the HTTP client boundary.
  • Review ignoreErrors regularly, since it can hide real problems.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

Jest fails to parse a React Native or Expo dependency

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax

Jest does not run Babel on node_modules by default, and many React Native packages ship untranspiled source.

3 causes, each with a fix

Web apps

TypeScript says a JavaScript module implicitly has an any type

Could not find a declaration file for module 'react-materialize'. 'path/to/module-name.js' implicitly has an 'any' type.

TypeScript found the JavaScript file but no types for it, and noImplicitAny turns that into an error.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.