From df5582a61622d18f8b2101acce45ccb467fd8ece Mon Sep 17 00:00:00 2001 From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com> Date: Tue, 28 Jun 2022 17:42:33 -0500 Subject: [PATCH] Call WP action hook that allow other consuming code to set a custom additional error reporting logic for Error Boundaries --- .../customize-widgets/src/components/error-boundary/index.js | 3 +++ .../edit-navigation/src/components/error-boundary/index.js | 3 +++ packages/edit-site/src/components/error-boundary/index.js | 5 +++++ packages/edit-widgets/src/components/error-boundary/index.js | 3 +++ packages/editor/src/components/error-boundary/index.js | 3 +++ 5 files changed, 17 insertions(+) diff --git a/packages/customize-widgets/src/components/error-boundary/index.js b/packages/customize-widgets/src/components/error-boundary/index.js index 17047e7f546ea..d2a057ec254ae 100644 --- a/packages/customize-widgets/src/components/error-boundary/index.js +++ b/packages/customize-widgets/src/components/error-boundary/index.js @@ -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 ); @@ -26,6 +27,8 @@ export default class ErrorBoundary extends Component { componentDidCatch( error ) { this.setState( { error } ); + + doAction( 'gb.reportErrorBoundaryException', error ); } render() { diff --git a/packages/edit-navigation/src/components/error-boundary/index.js b/packages/edit-navigation/src/components/error-boundary/index.js index bea03d909c380..75c253161f853 100644 --- a/packages/edit-navigation/src/components/error-boundary/index.js +++ b/packages/edit-navigation/src/components/error-boundary/index.js @@ -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() { @@ -19,6 +20,8 @@ class ErrorBoundary extends Component { componentDidCatch( error ) { this.setState( { error } ); + + doAction( 'gb.reportErrorBoundaryException', error ); } reboot() { diff --git a/packages/edit-site/src/components/error-boundary/index.js b/packages/edit-site/src/components/error-boundary/index.js index 35387fe5399c1..82c28452516b2 100644 --- a/packages/edit-site/src/components/error-boundary/index.js +++ b/packages/edit-site/src/components/error-boundary/index.js @@ -3,6 +3,7 @@ */ import { Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { doAction } from '@wordpress/hooks'; /** * Internal dependencies @@ -20,6 +21,10 @@ export default class ErrorBoundary extends Component { }; } + componentDidCatch( error ) { + doAction( 'gb.reportErrorBoundaryException', error ); + } + static getDerivedStateFromError( error ) { return { error }; } diff --git a/packages/edit-widgets/src/components/error-boundary/index.js b/packages/edit-widgets/src/components/error-boundary/index.js index cf2098a30844d..1399a85cd9cd6 100644 --- a/packages/edit-widgets/src/components/error-boundary/index.js +++ b/packages/edit-widgets/src/components/error-boundary/index.js @@ -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 ); @@ -29,6 +30,8 @@ export default class ErrorBoundary extends Component { componentDidCatch( error ) { this.setState( { error } ); + + doAction( 'gb.reportErrorBoundaryException', error ); } reboot() { diff --git a/packages/editor/src/components/error-boundary/index.js b/packages/editor/src/components/error-boundary/index.js index c7d0824a3dee2..85bd6abbacb0a 100644 --- a/packages/editor/src/components/error-boundary/index.js +++ b/packages/editor/src/components/error-boundary/index.js @@ -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 @@ -36,6 +37,8 @@ class ErrorBoundary extends Component { componentDidCatch( error ) { this.setState( { error } ); + + doAction( 'gb.reportErrorBoundaryException', error ); } reboot() {