diff --git a/js/components/errorHandling/errorBoundary.js b/js/components/errorHandling/errorBoundary.js
index 0e07697b4..b4b24a3c9 100644
--- a/js/components/errorHandling/errorBoundary.js
+++ b/js/components/errorHandling/errorBoundary.js
@@ -10,43 +10,52 @@ import { snackbarColors } from '../header/constants';
export class ErrorBoundary extends Component {
constructor(props) {
super(props);
- this.state = { error: null, errorInfo: null };
+ this.state = { caughtError: null, errorInfo: null };
}
- componentDidCatch(error, errorInfo) {
- // Catch errors in any components below and re-render with error message
- this.setState({
- error: error,
- errorInfo: errorInfo
- });
+ handleErrorData(error, errorInfo) {
// You can also log error messages to an error reporting service here
if (process.env.NODE_ENV === 'production') {
- Sentry.configureScope(scope => {
- Object.keys(errorInfo).forEach(key => {
- scope.setExtra(key, errorInfo[key]);
+ if (errorInfo) {
+ Sentry.configureScope(scope => {
+ Object.keys(errorInfo).forEach(key => {
+ scope.setExtra(key, errorInfo[key]);
+ });
});
- });
+ }
Sentry.captureException(error);
}
}
+ componentDidCatch(error, errorInfo) {
+ // Catch errors in any components below and re-render with error message
+ this.setState({
+ caughtError: error,
+ errorInfo: errorInfo
+ });
+ this.handleErrorData(error, errorInfo);
+ }
+
render() {
const { children } = this.props;
- const { error } = this.state;
+ const { caughtError } = this.state;
//render fallback UI
return (
<>
{children}
- {error !== null && (
-
- {({ setSnackBarTitle, setSnackBarColor }) => {
+
+ {({ error, setSnackBarTitle, setSnackBarColor }) => {
+ if (error || caughtError !== null) {
+ if (error) {
+ this.handleErrorData(error);
+ }
setSnackBarTitle('Something went wrong!');
- setSnackBarColor(snackbarColors.default);
- return null;
- }}
-
- )}
+ setSnackBarColor(snackbarColors.error);
+ }
+ return null;
+ }}
+
>
);
}
diff --git a/js/components/header/headerContext.js b/js/components/header/headerContext.js
index 7fc0a3d04..1c10d59d1 100644
--- a/js/components/header/headerContext.js
+++ b/js/components/header/headerContext.js
@@ -10,6 +10,7 @@ export const HeaderProvider = memo(props => {
const [headerButtons, setHeaderButtons] = useState(null);
const [snackBarTitle, setSnackBarTitle] = useState(null);
const [snackBarColor, setSnackBarColor] = useState(snackbarColors.default);
+ const [error, setError] = useState();
return (
{
snackBarTitle,
setSnackBarTitle,
snackBarColor,
- setSnackBarColor
+ setSnackBarColor,
+ error,
+ setError
}}
>
{props.children}
diff --git a/js/components/landing/Landing.js b/js/components/landing/Landing.js
index bf25ac02a..fb90a8785 100644
--- a/js/components/landing/Landing.js
+++ b/js/components/landing/Landing.js
@@ -2,7 +2,7 @@
* Created by ricgillams on 21/06/2018.
*/
import { Grid } from '@material-ui/core';
-import React, { memo, useEffect, useState } from 'react';
+import React, { memo, useEffect } from 'react';
import TargetList from '../target/targetList';
import SessionList from '../session/sessionList';
import { connect } from 'react-redux';
@@ -11,7 +11,6 @@ import * as selectionActions from '../../reducers/selection/actions';
import { DJANGO_CONTEXT } from '../../utils/djangoContext';
const Landing = memo(({ resetSelectionState, resetTargetState }) => {
- const [state, setState] = useState();
let text_div;
if (DJANGO_CONTEXT['authenticated'] === true) {
@@ -37,15 +36,7 @@ const Landing = memo(({ resetSelectionState, resetTargetState }) => {
- {
- setState(() => {
- throw Error('my custom error');
- });
- }}
- >
- Welcome to Fragalysis
-
+ Welcome to Fragalysis
{text_div}
diff --git a/js/components/preview/compounds/compoundView.js b/js/components/preview/compounds/compoundView.js
index 873ad185f..4d0b415ed 100644
--- a/js/components/preview/compounds/compoundView.js
+++ b/js/components/preview/compounds/compoundView.js
@@ -8,6 +8,7 @@ import { VIEWS } from '../../../constants/constants';
import { NglContext } from '../../nglView/nglProvider';
import { compoundsColors } from './redux/constants';
import { handleClickOnCompound, loadCompoundImageData } from './redux/dispatchActions';
+import { HeaderContext } from '../../header/headerContext';
export const loadingCompoundImage = `