-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7d3c28
commit db3cef2
Showing
9 changed files
with
305 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,31 @@ | ||
import React, {Component} from 'react'; | ||
import React from 'react'; | ||
import {DefaultLayoutComponent} from 'layouts/default-layout'; | ||
import {Alert} from 'react-bootstrap'; | ||
import getConfig from 'next/config'; | ||
import * as Sentry from '@sentry/react'; | ||
|
||
class ErrorBoundary extends Component { | ||
state = {hasError: false, error: null, errorInfo: null}; | ||
const ErrorBoundary: React.FunctionComponent = ({children}) => { | ||
const supportEmail = getConfig()?.publicRuntimeConfig.SUPPORT_EMAIL; | ||
const mailtoLink = `mailto:${supportEmail}?subject=Support Request: CIIP Website Server Error`; | ||
|
||
static getDerivedStateFromError(error) { | ||
// Update state so the next render will show the fallback UI. | ||
console.error(error); | ||
return {hasError: true}; | ||
} | ||
|
||
componentDidCatch(error, errorInfo) { | ||
// You can also log the error to an error reporting service | ||
// logErrorToMyService(error, errorInfo); | ||
this.setState({error, errorInfo}); | ||
console.error(error, errorInfo); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
const supportEmail = getConfig()?.publicRuntimeConfig.SUPPORT_EMAIL; | ||
const mailtoLink = `mailto:${supportEmail}?subject=Support Request: CIIP Website Server Error`; | ||
// You can render any custom fallback UI | ||
return ( | ||
return ( | ||
<Sentry.ErrorBoundary | ||
fallback={ | ||
<DefaultLayoutComponent session={null}> | ||
<Alert variant="danger"> | ||
<Alert.Heading>An unexpected error has occured</Alert.Heading> | ||
<Alert.Heading>Something went wrong</Alert.Heading> | ||
<p> | ||
Please consider reporting this error to our development team at{' '} | ||
<Alert.Link href={mailtoLink}>{supportEmail}</Alert.Link>. Copying | ||
the error details below when submitting a bug report will help us | ||
understand what happened. | ||
Our development team was automatically notified. If you continue | ||
to encounter this problem, consider contacting us at{' '} | ||
<Alert.Link href={mailtoLink}>{supportEmail}</Alert.Link>. | ||
</p> | ||
</Alert> | ||
|
||
<h3>Error details</h3> | ||
<pre> | ||
<code> | ||
{this.state.error?.toString()} | ||
{process.env.NODE_ENV !== 'production' && | ||
this.state.errorInfo?.componentStack} | ||
</code> | ||
</pre> | ||
</DefaultLayoutComponent> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
} | ||
> | ||
{children} | ||
</Sentry.ErrorBoundary> | ||
); | ||
}; | ||
|
||
export default ErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
const path = require('path'); | ||
const Dotenv = require('dotenv-webpack'); | ||
const {withSentryConfig} = require('@sentry/nextjs'); | ||
const dotenv = require('dotenv'); | ||
dotenv.config(); | ||
|
||
module.exports = { | ||
cssModules: true, | ||
webpack: (config) => { | ||
config.plugins = config.plugins || []; | ||
module.exports = withSentryConfig( | ||
{ | ||
cssModules: true, | ||
webpack: (config) => { | ||
config.plugins = config.plugins || []; | ||
|
||
config.plugins = [ | ||
...config.plugins, | ||
config.plugins = [ | ||
...config.plugins, | ||
// Read the .env file | ||
new Dotenv({ | ||
path: path.join(__dirname, '.env'), | ||
systemvars: true | ||
}) | ||
]; | ||
|
||
// Read the .env file | ||
new Dotenv({ | ||
path: path.join(__dirname, '.env'), | ||
systemvars: true | ||
}) | ||
]; | ||
|
||
return config; | ||
return config; | ||
}, | ||
publicRuntimeConfig: { | ||
ADMIN_EMAIL: process.env.ADMIN_EMAIL, | ||
SUPPORT_EMAIL: process.env.SUPPORT_EMAIL, | ||
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, | ||
SITEWIDE_NOTICE: process.env.SITEWIDE_NOTICE, | ||
ENABLE_DB_MOCKS: process.env.ENABLE_DB_MOCKS | ||
} | ||
}, | ||
publicRuntimeConfig: { | ||
ADMIN_EMAIL: process.env.ADMIN_EMAIL, | ||
SUPPORT_EMAIL: process.env.SUPPORT_EMAIL, | ||
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, | ||
SITEWIDE_NOTICE: process.env.SITEWIDE_NOTICE, | ||
ENABLE_DB_MOCKS: process.env.ENABLE_DB_MOCKS | ||
{ | ||
// set to false to create a sentry release and upload sourcemaps | ||
dryRun: true, | ||
silent: true | ||
} | ||
}; | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This file configures the initialization of Sentry on the browser. | ||
// The config you add here will be used whenever a page is visited. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
const SENTRY_DSN = process.env.SENTRY_ENVIRONMENT | ||
? 'https://0c7b819c89924f4abe36297bf7cbc7cb@o646776.ingest.sentry.io/5797775' | ||
: null; | ||
|
||
Sentry.init({ | ||
dsn: SENTRY_DSN | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This file configures the initialization of Sentry on the server. | ||
// The config you add here will be used whenever the server handles a request. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
const SENTRY_DSN = process.env.SENTRY_ENVIRONMENT | ||
? 'https://0c7b819c89924f4abe36297bf7cbc7cb@o646776.ingest.sentry.io/5797775' | ||
: null; | ||
|
||
Sentry.init({ | ||
dsn: SENTRY_DSN | ||
}); |
Oops, something went wrong.