Skip to content

Commit

Permalink
Merge pull request #43 from nsidc/error-handling
Browse files Browse the repository at this point in the history
Error handling
  • Loading branch information
mfisher87 authored Oct 18, 2023
2 parents 158fb7d + 9fee889 commit 3bbba4a
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 139 deletions.
286 changes: 155 additions & 131 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
"react": "^18.2.0",
"react-bootstrap": "~1.6.5",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-icons": "^4.4.0",
"react-rnd": "^10.3.7",
"recoil": "^0.7.4"
"recoil": "^0.7.7"
},
"devDependencies": {
"@babel/preset-env": "^7.18.6",
Expand Down
10 changes: 8 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React from 'react';
import { ErrorBoundary } from 'react-error-boundary';

import pkg from '../package.json';
import './style/App.css';
import './style/error.css';
import ControlPanel from './components/ControlPanel';
import TileLayout from './components/TileLayout';
import ErrorFallbackComponent from './components/ErrorFallback';


const App: React.FC = () => {
return (
<div className={"App"}>
<div id={"version"}>v{pkg.version}</div>

<ControlPanel />
<TileLayout />
<ErrorBoundary FallbackComponent={ErrorFallbackComponent}>
<ControlPanel />
<TileLayout />
</ErrorBoundary>

</div>
);
Expand Down
21 changes: 21 additions & 0 deletions src/components/ErrorFallback.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type ErrorFallbackParams = {error: Error, resetErrorBoundary: () => void};
const ErrorFallbackComponent = ({error, resetErrorBoundary}: ErrorFallbackParams) => (
<div role="alert" className="error">
<h3>Woops!</h3>

<div className="error-message">{error.message}</div>

<p>
It's likely this application is down because other web services it depends on are currently down.
Refresh the page later to try again.
</p>

<p><b>
{"Please contact "}
<a href="mailto:[email protected]">NSIDC User Services</a>
{" if you need additional assistance."}
</b></p>
</div>
);

export default ErrorFallbackComponent;
14 changes: 9 additions & 5 deletions src/components/Tile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import {useRecoilValue} from 'recoil';

import '../style/card.css';
Expand All @@ -10,6 +11,7 @@ import selectedSatelliteVariableObjectAtom from '../state/client/derived/selecte
import selectedTileTypeAtom from '../state/client/selectedTileType';
import LinePlot from './LinePlot';
import SlippyMap from './SlippyMap';
import ErrorFallbackComponent from './ErrorFallback';


type ITileProps = ITileIdentifier & {style: React.CSSProperties};
Expand Down Expand Up @@ -44,12 +46,14 @@ const Tile: React.FC<ITileProps> = (props) => {
throw new Error('This can not happen!');
}
return (
<div className={'Tile snow-today-card'} style={props.style}>
{content}
<div className='tile-citation'>
{CITATION}
<div className={'Tile snow-today-card'} style={props.style}>
<ErrorBoundary FallbackComponent={ErrorFallbackComponent}>
{content}
<div className='tile-citation'>
{CITATION}
</div>
</ErrorBoundary>
</div>
</div>
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/serverState/plotData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const usePlotDataQuery = (
staleTime: Infinity,
// Don't retry failed requests; in this case there is no plot!
retry: false,
// Propagate all errors to the nearest error boundary
useErrorBoundary: true,
},
);
export default usePlotDataQuery;
2 changes: 2 additions & 0 deletions src/serverState/regionShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const useRegionShapeQuery = (regionShapeFilePath: string | undefined) => useQuer
// Never re-fetch this data!
cacheTime: Infinity,
staleTime: Infinity,
// Propagate all errors to the nearest error boundary
useErrorBoundary: true,
},
);
export default useRegionShapeQuery;
2 changes: 2 additions & 0 deletions src/serverState/regionsIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const useRegionsIndexQuery = (
// Never re-fetch this data!
cacheTime: Infinity,
staleTime: Infinity,
// Propagate all errors to the nearest error boundary
useErrorBoundary: true,
}
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/serverState/variablesIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const useVariablesIndexQuery = (
// Never re-fetch this data!
cacheTime: Infinity,
staleTime: Infinity,
// Propagate all errors to the nearest error boundary
useErrorBoundary: true,
}
);
}
Expand Down
14 changes: 14 additions & 0 deletions src/style/error.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.error {
margin: 10px;
}

.error-message {
font-family: monospace;
white-space: pre;

margin: 10px;
padding: 10px;

background-color: whitesmoke;
color: red;
}

0 comments on commit 3bbba4a

Please sign in to comment.