1- import React , { Component } from 'react'
1+ import React , { Component , ErrorInfo , ReactNode } from 'react'
22import { Stack } from 'office-ui-fabric-react'
33import Spinner from 'widgets/Spinner'
44import { handleViewError } from 'services/remote'
55
6- const handleError = ( error : Error ) => {
7- handleViewError ( error . toString ( ) )
6+ const handleError = ( error : Error , errorInfo ?: ErrorInfo ) => {
7+ handleViewError (
8+ JSON . stringify ( [
9+ `UI crash: ${ error . message } ` ,
10+ {
11+ stack : error . stack ,
12+ componentStack : errorInfo ?. componentStack || 'N/A' ,
13+ } ,
14+ ] )
15+ )
816 if ( import . meta. env . MODE !== 'development' ) {
917 window . location . reload ( )
1018 }
11- return { hasError : true }
1219}
1320
14- class ErrorBoundary extends Component < { children : React . ReactChild } , { hasError : boolean } > {
15- constructor ( props : { children : React . ReactChild } ) {
21+ class ErrorBoundary extends Component < { children : ReactNode } , { hasError : boolean } > {
22+ constructor ( props : { children : ReactNode } ) {
1623 super ( props )
1724 this . state = {
1825 hasError : false ,
@@ -23,8 +30,9 @@ class ErrorBoundary extends Component<{ children: React.ReactChild }, { hasError
2330 return handleError ( error )
2431 }
2532
26- public componentDidCatch ( error : Error ) {
27- this . setState ( handleError ( error ) )
33+ public componentDidCatch ( error : Error , errorInfo : ErrorInfo ) {
34+ handleError ( error , errorInfo )
35+ this . setState ( { hasError : true } )
2836 }
2937
3038 render ( ) {
0 commit comments