11import { Button } from '@gear-js/vara-ui' ;
2- import { Component , ReactNode } from 'react' ;
2+ import { ErrorBoundary as SentryErrorBoundary , FallbackRender } from '@sentry/react' ;
3+ import { ComponentProps , PropsWithChildren } from 'react' ;
34import { useLocation , useNavigate } from 'react-router-dom' ;
45
56import { useChangeEffect } from '@/hooks' ;
@@ -8,56 +9,27 @@ import { Container } from '../container';
89
910import styles from './error-boundary.module.scss' ;
1011
11- type Props = {
12- children : ReactNode ;
13- } ;
14-
15- type FallbackProps = {
16- message : string ;
17- reset : ( ) => void ;
18- } ;
19-
20- type State = {
21- error : Error | null ;
22- } ;
23-
24- function Fallback ( { message, reset } : FallbackProps ) {
12+ // eslint-disable-next-line @typescript-eslint/unbound-method
13+ function Fallback ( { error, resetError } : ComponentProps < FallbackRender > ) {
2514 const { pathname } = useLocation ( ) ;
2615 const navigate = useNavigate ( ) ;
2716
2817 useChangeEffect ( ( ) => {
29- reset ( ) ;
18+ resetError ( ) ;
3019 } , [ pathname ] ) ;
3120
3221 return (
3322 < Container >
3423 < h2 className = { styles . heading } > Oops! Something went wrong:</ h2 >
35- < p className = { styles . error } > { message } </ p >
24+ < p className = { styles . error } > { error instanceof Error ? error . message : String ( error ) } </ p >
3625
3726 < Button text = "Go Back" size = "small" onClick = { ( ) => navigate ( - 1 ) } />
3827 </ Container >
3928 ) ;
4029}
4130
42- class ErrorBoundary extends Component < Props , State > {
43- constructor ( props : Props ) {
44- super ( props ) ;
45- this . state = { error : null } ;
46- }
47-
48- static getDerivedStateFromError ( error : Error ) {
49- return { error } ;
50- }
51-
52- reset = ( ) => {
53- this . setState ( { error : null } ) ;
54- } ;
55-
56- render ( ) {
57- if ( ! this . state . error ) return this . props . children ;
58-
59- return < Fallback message = { this . state . error . message } reset = { this . reset } /> ;
60- }
31+ function ErrorBoundary ( { children } : PropsWithChildren ) {
32+ return < SentryErrorBoundary fallback = { Fallback } > { children } </ SentryErrorBoundary > ;
6133}
6234
6335export { ErrorBoundary } ;
0 commit comments