Skip to content

Commit

Permalink
Call WP action hook that allow other consuming code to set a custom a…
Browse files Browse the repository at this point in the history
…dditional error reporting logic for Error Boundaries
  • Loading branch information
fullofcaffeine committed Jun 28, 2022
1 parent 4e0893b commit df5582a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Warning } from '@wordpress/block-editor';
import { useCopyToClipboard } from '@wordpress/compose';
import { doAction } from '@wordpress/hooks';

function CopyButton( { text, children } ) {
const ref = useCopyToClipboard( text );
Expand All @@ -26,6 +27,8 @@ export default class ErrorBoundary extends Component {

componentDidCatch( error ) {
this.setState( { error } );

doAction( 'gb.reportErrorBoundaryException', error );
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Warning } from '@wordpress/block-editor';
import { doAction } from '@wordpress/hooks';

class ErrorBoundary extends Component {
constructor() {
Expand All @@ -19,6 +20,8 @@ class ErrorBoundary extends Component {

componentDidCatch( error ) {
this.setState( { error } );

doAction( 'gb.reportErrorBoundaryException', error );
}

reboot() {
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-site/src/components/error-boundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { doAction } from '@wordpress/hooks';

/**
* Internal dependencies
Expand All @@ -20,6 +21,10 @@ export default class ErrorBoundary extends Component {
};
}

componentDidCatch( error ) {
doAction( 'gb.reportErrorBoundaryException', error );
}

static getDerivedStateFromError( error ) {
return { error };
}
Expand Down
3 changes: 3 additions & 0 deletions packages/edit-widgets/src/components/error-boundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Warning } from '@wordpress/block-editor';
import { useCopyToClipboard } from '@wordpress/compose';
import { doAction } from '@wordpress/hooks';

function CopyButton( { text, children } ) {
const ref = useCopyToClipboard( text );
Expand All @@ -29,6 +30,8 @@ export default class ErrorBoundary extends Component {

componentDidCatch( error ) {
this.setState( { error } );

doAction( 'gb.reportErrorBoundaryException', error );
}

reboot() {
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/components/error-boundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button } from '@wordpress/components';
import { select } from '@wordpress/data';
import { Warning } from '@wordpress/block-editor';
import { useCopyToClipboard } from '@wordpress/compose';
import { doAction } from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -36,6 +37,8 @@ class ErrorBoundary extends Component {

componentDidCatch( error ) {
this.setState( { error } );

doAction( 'gb.reportErrorBoundaryException', error );
}

reboot() {
Expand Down

0 comments on commit df5582a

Please sign in to comment.