Sentry: Non-Error promise rejection captured with value in a React app
Non-Error promise rejection captured with value: Object Not Found Matching IdShort 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.
Fix it fast
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__2Match what you see, then jump to its fix
- 1
The event has __serialized__ data and no useful stack traceYour code rejects or throws a plain object or stringFix - 2
The object comes from a third-party client or an API wrapperA library rejects with an object you cannot changeFix - 3
Events appear for rejections you already handle elsewhereUnhandled rejections are captured automatically and you want controlFix
- 1
What does the error look like?
Non-Error promise rejection captured with value: Object Not Found Matching IdNon-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 SentryConfirmed by docs.sentry.io
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.js2Fix
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 countConfirmed by docs.sentry.io
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 SentryConfirmed by docs.sentry.io
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
A React component crashes while destructuring props or state
TypeError: Cannot destructure property 'b' of 'null' as it is null.
JavaScript throws this when the right side of a destructuring pattern is undefined or null.
3 causes, each with a fixWeb 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 fixWeb 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 fixWeb apps
TypeError: undefined is not iterable when destructuring a hook or array
TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
Array destructuring, spread, for...of and new Set all need an iterable.
4 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fix