From c33ff771da9fbeb01e9b30e0289006cf0c1f967e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 21 Oct 2023 15:52:37 -0500 Subject: [PATCH] SiteErrorBoundary: rework conditionals for Sentry and production --- src/components/site-error-boundary.tsx | 67 ++++++++++++++------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/components/site-error-boundary.tsx b/src/components/site-error-boundary.tsx index 4732ad27e..698cd6ea0 100644 --- a/src/components/site-error-boundary.tsx +++ b/src/components/site-error-boundary.tsx @@ -18,13 +18,14 @@ interface ISiteErrorBoundary { /** Application-level error boundary. Fills the whole screen. */ const SiteErrorBoundary: React.FC = ({ children }) => { - const { links } = useSoapboxConfig(); + const { links, sentryDsn } = useSoapboxConfig(); const textarea = useRef(null); const [error, setError] = useState(); const [componentStack, setComponentStack] = useState(); const [browser, setBrowser] = useState(); + const sentryEnabled = Boolean(sentryDsn); const isProduction = NODE_ENV === 'production'; const errorText = String(error) + componentStack; @@ -52,18 +53,16 @@ const SiteErrorBoundary: React.FC = ({ children }) => { setError(error); setComponentStack(info.componentStack); - if (isProduction) { - captureSentryException(error, { - tags: { - // Allow page crashes to be easily searched in Sentry. - ErrorBoundary: 'yes', - }, - }); + captureSentryException(error, { + tags: { + // Allow page crashes to be easily searched in Sentry. + ErrorBoundary: 'yes', + }, + }); - import('bowser') - .then(({ default: Bowser }) => setBrowser(Bowser.getParser(window.navigator.userAgent))) - .catch(() => {}); - } + import('bowser') + .then(({ default: Bowser }) => setBrowser(Bowser.getParser(window.navigator.userAgent))) + .catch(() => {}); } function goHome() { @@ -116,27 +115,31 @@ const SiteErrorBoundary: React.FC = ({ children }) => { - {!isProduction && ( -
- {errorText && ( -