import React, { FunctionComponent, PropsWithChildren } from 'react'; import { ErrorBoundary as ErrorBound, FallbackProps, withErrorBoundary } from 'react-error-boundary'; import * as Sentry from '@sentry/electron'; export const ErrorBoundary = (props: PropsWithChildren<{}>) => { const myErrorHandler = (error: Error, info: any) => { console.error('error: ', error); const componentStack = info.componentStack; Sentry.withScope((scope) => { scope.setExtras({ componentStack }); Sentry.captureException(error); }); }; return ( {props.children} ); }; const ErrorFallback: FunctionComponent = (props: FallbackProps) => { const { error, resetErrorBoundary } = props; return ( There was an error in loading this page.{' '} Reload this page {' '} Click for error details {error?.message} ); }; export const WithHandler = (ComponentThatMayError: any) => { return withErrorBoundary(ComponentThatMayError, { FallbackComponent: ErrorFallback, onError(error: Error, info: any) { console.error('error: ', error); const componentStack = info.componentStack; Sentry.withScope((scope) => { scope.setExtras({ componentStack }); Sentry.captureException(error); }); }, }); };
There was an error in loading this page.{' '} Reload this page {' '}
{error?.message}