Skip to content

Commit

Permalink
Setup action hook callback to capture React Error Boundary exceptions…
Browse files Browse the repository at this point in the history
… in Gutenberg with Sentry (#65503)

Register a callback to `editor.ErrorBoundary.errorLogged` action that will forward the error to Sentry everytime the action is called.

The action has been added to all active React Error Boundaries in Gutenberg in the following changeset: WordPress/gutenberg#42024 .
  • Loading branch information
fullofcaffeine authored Aug 5, 2022
1 parent 346222f commit 8f3ed09
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Sentry from '@sentry/browser';
import apiFetch from '@wordpress/api-fetch';
import { addAction } from '@wordpress/hooks';

const shouldActivateSentry = window.A8C_ETK_ErrorReporting_Config?.shouldActivateSentry === 'true';
/**
Expand All @@ -18,6 +19,12 @@ function activateSentry() {
release: 'wpcom-test-01',
} );

// Capture exceptions from Gutenberg React Error Boundaries
addAction( 'editor.ErrorBoundary.errorLogged', 'etk/error-reporting', ( error ) => {
// error is the exception's error object
Sentry.captureException( error );
} );

// We still need to report the head errors, if any.
headErrors.forEach( ( error ) => Sentry.captureException( error ) );
Sentry.flush().then( () => delete window._jsErr );
Expand Down

0 comments on commit 8f3ed09

Please sign in to comment.