diff --git a/libs/shared/lib/components/ErrorBoundary/ErrorBoundary.tsx b/libs/shared/lib/components/ErrorBoundary/ErrorBoundary.tsx index 20470b3ab2c8f3f47feb91afcd995918d58f694f..4156ca2315b9b385dbf1624b68c0a2575fe2ac56 100644 --- a/libs/shared/lib/components/ErrorBoundary/ErrorBoundary.tsx +++ b/libs/shared/lib/components/ErrorBoundary/ErrorBoundary.tsx @@ -1,16 +1,21 @@ import React, { ReactNode } from 'react'; import { Button } from '../buttons'; +import { useAuthorizationCache, useSessionCache } from '../../data-access'; +// import * as Sentry from '@sentry/react'; interface ErrorBoundaryProps { fallback: ReactNode; children: ReactNode; + saveStateID?: string; + userID?: string; + sessionID?: string; } interface ErrorBoundaryState { hasError: boolean; } -class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> { +class ErrorBoundaryWrapper extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> { constructor(props: ErrorBoundaryProps) { super(props); this.state = { hasError: false }; @@ -21,8 +26,18 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta } componentDidCatch(error: Error, info: React.ErrorInfo): void { - console.log('An error happened in the application'); - // send to error logging service in the future + console.log('An error happened in the application', import.meta.env); + if (import.meta.env.SENTRY_ENABLED) { + // send to error logging service in the future + // Sentry.captureException(error, { + // userID: this.props.userID, + // sessionID: this.props.sessionID, + // saveState: this.props.saveStateID, + // error, + // info, + // }); + console.log('log to sentry'); + } } resetErrorBoundary = () => { @@ -46,4 +61,15 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta } } +const ErrorBoundary: React.FC<{ fallback: ReactNode; children: ReactNode }> = (props) => { + const session = useSessionCache(); + const auth = useAuthorizationCache(); + + return ( + <ErrorBoundaryWrapper {...props} userID={auth.userID} sessionID={auth.sessionID} saveStateID={session.currentSaveState}> + {props.children} + </ErrorBoundaryWrapper> + ); +}; + export { ErrorBoundary }; diff --git a/libs/shared/lib/vis/components/VisualizationPanel.tsx b/libs/shared/lib/vis/components/VisualizationPanel.tsx index 39ed4d1122352318a0fc2bdd82e514d2ca135d7d..86bcc67641d61b224b3465997a705c4cb82783a7 100644 --- a/libs/shared/lib/vis/components/VisualizationPanel.tsx +++ b/libs/shared/lib/vis/components/VisualizationPanel.tsx @@ -8,6 +8,7 @@ import { useML, useQuerybuilderGraph, useSchemaGraph, + useSessionCache, useVisualization, } from '@graphpolaris/shared/lib/data-access'; import VisualizationTabBar from './VisualizationTabBar';