Skip to content

Commit

Permalink
🥅 Capture errors in ErrorBoundary with Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Jan 28, 2025
1 parent 5fe274a commit a32d636
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ViteJS based
VITE_VERSION=latest
VITE_MUTE_ERROR_BOUNDARY_LOG=false
VITE_BASE_API_URL=http://localhost:8000/api/v2/
VITE_FORM_ID=93c09209-5fb9-4105-b6bb-9d9f0aa6782c
VITE_USE_HASH_ROUTING=false
10 changes: 8 additions & 2 deletions src/components/Errors/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/react';
import {getEnv} from 'env.mjs';
import PropTypes from 'prop-types';
import React from 'react';
import {FormattedMessage, useIntl} from 'react-intl';
Expand All @@ -14,7 +16,12 @@ import {DEBUG} from 'utils';
import ErrorMessage from './ErrorMessage';

const logError = (error, errorInfo) => {
if (DEBUG) console.error(error, errorInfo);
if (DEBUG) {
const muteConsole = getEnv('MUTE_ERROR_BOUNDARY_LOG');
if (!muteConsole) console.error(error, errorInfo);
} else {
Sentry.captureException(error);
}
};

class ErrorBoundary extends React.Component {
Expand All @@ -31,7 +38,6 @@ class ErrorBoundary extends React.Component {
}

componentDidCatch(error, errorInfo) {
// TODO: depending on the error type, send to sentry?
logError(error, errorInfo);
}

Expand Down

0 comments on commit a32d636

Please sign in to comment.