Sentry Simple Example 🚨

Image Source

This example demonstrates how to record unhandled exceptions in your code with Sentry. There are several test pages below that result in various kinds of unhandled exceptions.

Important: exceptions in development mode take a different path than in production. These tests should be run on a production build (i.e. 'next build'). Read more

  1. API route exceptions (note that 1-3 are not expected to work if deployed to Vercel yet)
    1. API has a top-of-module Promise that rejects, but its result is not awaited. Sentry should record Error('API Test 1'). Open in a new tab
    2. API has a top-of-module exception. Sentry should record Error('API Test 2'). Open in a new tab
    3. API has has an exception in its request handler. Sentry should record Error('API Test 3'). Open in a new tab
    4. API uses a try/catch to handle an exception and records it. Sentry should record Error('API Test 4'). Open in a new tab
  2. SSR exceptions
    1. getServerSideProps throws an Error. This should cause _error.js to render and record Error('SSR Test 1') in Sentry. Open in a new tab or Perform client side navigation
    2. getServerSideProps returns a Promise that rejects. This should cause _error.js to render and record Error('SSR Test 2') in Sentry. Open in a new tab
    3. getServerSideProps calls a Promise that rejects, but does not handle the rejection or await its result (returning synchronously). Sentry should record Error('SSR Test 3'), but will not when deployed to Vercel because the serverless function will already have exited. Open in a new tab
    4. getServerSideProps manually captures an exception from a try/catch. This should record Error('SSR Test 4') in Sentry. Open in a new tab
  3. Client exceptions
    1. There is a top-of-module Promise that rejects, but its result is not awaited. Sentry should record Error('Client Test 1'). Perform client side navigation or Open in a new tab
    2. There is a top-of-module exception. _error.js should render and record ReferenceError('process is not defined') in Sentry. Perform client side navigation or Open in a new tab
    3. There is an exception during React lifecycle that is caught by Next.js's React Error Boundary. In this case, when the component mounts. This should cause _error.js to render and record Error('Client Test 3') in Sentry. Perform client side navigation or Open in a new tab
    4. There is an unhandled Promise rejection during React lifecycle. In this case, when the component mounts. Sentry should record Error('Client Test 4'). Perform client side navigation or Open in a new tab
    5. An Error is thrown from an event handler. Sentry should record Error('Client Test 5'). Perform client side navigation or Open in a new tab