Add Sentry to client for error handling (#43920)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Tristan Toye
2022-04-15 10:54:02 -04:00
committed by GitHub
parent 832eb29c0d
commit dfe5a7fd05
11 changed files with 478 additions and 16 deletions

View File

@@ -6,7 +6,8 @@ const {
localeChallengesRootDir
} = require('./utils/build-challenges');
const { clientLocale, curriculumLocale, homeLocation } = envData;
const { clientLocale, curriculumLocale, homeLocation, sentryClientDSN } =
envData;
const curriculumIntroRoot = path.resolve(__dirname, './src/pages');
const pathPrefix =
@@ -24,6 +25,12 @@ module.exports = {
},
pathPrefix: pathPrefix,
plugins: [
{
resolve: '@sentry/gatsby',
options: {
dsn: sentryClientDSN
}
},
{
resolve: 'gatsby-plugin-webpack-bundle-analyser-v2',
options: {

View File

@@ -49,6 +49,7 @@
"@freecodecamp/strip-comments": "3.0.1",
"@loadable/component": "5.15.2",
"@reach/router": "1.3.4",
"@sentry/gatsby": "^6.19.6",
"@stripe/react-stripe-js": "1.7.1",
"@stripe/stripe-js": "1.27.0",
"@types/react-scrollable-anchor": "0.6.1",

View File

@@ -1,7 +1,15 @@
// TODO: integrate with Sentry?
import * as Sentry from '@sentry/gatsby';
import envData from '../../../config/env.json';
const { sentryClientDSN } = envData;
export function reportClientSideError(
e: Error,
message = 'Unhandled error'
): void {
return console.error(`Client: ${message}`, e);
message = sentryClientDSN === null
? 'Unhandled error'
: 'Error sent to Sentry'
): string | void {
return sentryClientDSN === null
? console.error(`Client: ${message}`, e)
: Sentry.captureException(e);
}