---
title: "OnUnhandledRejection"
description: "Registers handlers to capture global unhandled promise rejections. (default)"
url: https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/integrations/unhandledrejection/
---

# OnUnhandledRejection | Sentry for AWS Lambda

This integration only works inside server environments (Node.js, Bun, Deno).

*Import name: `Sentry.onUnhandledRejectionIntegration`*

This integration is enabled by default. If you'd like to modify your default integrations, read [this](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/integrations.md#modifying-default-integrations).

The `onUnhandledRejectionIntegration` registers handlers to capture global unhandled promise rejections.

```JavaScript
Sentry.init({
  integrations: [Sentry.onUnhandledRejectionIntegration()],
});
```

## [On AWS Lambda](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/integrations/unhandledrejection.md#on-aws-lambda)

AWS adds their own `unhandledRejection` handlers to a lambda function which results in Sentry not being able to pick these up. As a workaround, remove all handlers before initializing Sentry.

Unfortunately, this means the AWS Lambda handler has to be [manually wrapped](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/install/layer.md#alternative-initialize-the-sdk-in-code).

```JavaScript
const Sentry = require("@sentry/aws-serverless");

// Remove `unhandledRejection` handlers set up by AWS so the
// Sentry SDK can capture these
process.removeAllListeners("unhandledRejection");

Sentry.init({
  dsn: "___PUBLIC_DSN___"
  // Add Tracing by setting tracesSampleRate and adding integration
  // Set tracesSampleRate to 1.0 to capture 100% of transactions
  // We recommend adjusting this value in production
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
  tracesSampleRate: 1.0,
});

exports.handler = Sentry.wrapHandler(async (event, context) => {
  // Your handler code
});
```

## [Options](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/integrations/unhandledrejection.md#options)

### [`mode`](https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/integrations/unhandledrejection.md#mode)

*Type: `'none' | 'warn' | 'strict'`*

This option defines what to do after capturing an unhandled rejection and mimics the behavior of [node's](https://nodejs.org/api/cli.html#--unhandled-rejectionsmode) `--unhandled-rejection` flag:

* `strict`: Raise the unhandled rejection as an uncaught exception. If the exception is handled, unhandledRejection is emitted.
* `warn`: Always trigger a warning, no matter if the unhandledRejection hook is set or not but do not print the deprecation warning.
* `none`: Silence all warnings.

Defaults to `warn`.
