This repository was archived by the owner on Feb 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +101
-0
lines changed
components/block-error-boundary
context/cart-checkout/checkout Expand file tree Collapse file tree 4 files changed +101
-0
lines changed Original file line number Diff line number Diff line change @@ -39,10 +39,14 @@ class BlockErrorBoundary extends Component {
3939 showErrorMessage,
4040 text,
4141 errorMessagePrefix,
42+ renderError,
4243 } = this . props ;
4344 const { errorMessage, hasError } = this . state ;
4445
4546 if ( hasError ) {
47+ if ( typeof renderError === 'function' ) {
48+ return renderError ( { errorMessage } ) ;
49+ }
4650 return (
4751 < BlockError
4852 errorMessage = { showErrorMessage ? errorMessage : null }
@@ -85,6 +89,10 @@ BlockErrorBoundary.propTypes = {
8589 * Text preceeding the error message.
8690 */
8791 errorMessagePrefix : PropTypes . string ,
92+ /**
93+ * Render function to show a custom error component.
94+ */
95+ renderError : PropTypes . func ,
8896} ;
8997
9098BlockErrorBoundary . defaultProps = {
Original file line number Diff line number Diff line change 1+ /**
2+ * External dependencies
3+ */
4+ import { PluginArea } from '@wordpress/plugins' ;
5+ import { CURRENT_USER_IS_ADMIN } from '@woocommerce/block-settings' ;
6+ import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary' ;
7+
18/**
29 * Internal dependencies
310 */
@@ -31,6 +38,15 @@ export const CheckoutProvider = ( {
3138 < ShippingDataProvider >
3239 < PaymentMethodDataProvider >
3340 { children }
41+ { /* If the current user is an admin, we let BlockErrorBoundary render
42+ the error, or we simply die silently. */ }
43+ < BlockErrorBoundary
44+ renderError = {
45+ CURRENT_USER_IS_ADMIN ? null : ( ) => null
46+ }
47+ >
48+ < PluginArea />
49+ </ BlockErrorBoundary >
3450 < CheckoutProcessor />
3551 </ PaymentMethodDataProvider >
3652 </ ShippingDataProvider >
Original file line number Diff line number Diff line change 153153 "@wordpress/autop" : " 2.9.0" ,
154154 "@wordpress/deprecated" : " 2.9.0" ,
155155 "@wordpress/notices" : " 2.9.1" ,
156+ "@wordpress/plugins" : " ^2.23.0" ,
156157 "@wordpress/wordcount" : " 2.11.0" ,
157158 "classnames" : " 2.2.6" ,
158159 "compare-versions" : " 3.6.0" ,
You can’t perform that action at this time.
0 commit comments