Skip to content

Commit

Permalink
testing error boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky committed Feb 16, 2024
1 parent 90bb234 commit 271db3c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"@bcgov/citz-imb-kc-react": "https://github.com/bcgov/citz-imb-kc-react/releases/download/v1.4.0/bcgov-citz-imb-kc-react-1.4.0.tgz",
"@emotion/react": "11.11.3",
"@emotion/styled": "11.11.0",
"@mui/icons-material": "5.15.6",
"@mdi/js": "7.4.47",
"@mdi/react": "1.6.1",
"@mui/icons-material": "5.15.6",
"@mui/material": "5.15.6",
"@mui/x-data-grid": "6.19.2",
"node-xlsx": "0.23.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-error-boundary": "4.0.12",
"react-hook-form": "7.50.1",
"react-router-dom": "6.22.0"
},
Expand Down
34 changes: 31 additions & 3 deletions react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import AuthRouteGuard from './guards/AuthRouteGuard';
import BaseLayout from './components/layout/BaseLayout';
import { AccessRequest } from './pages/AccessRequest';
import UsersManagement from './pages/UsersManagement';
import { ErrorBoundary } from 'react-error-boundary';
import { useNavigate } from 'react-router-dom';

const Router = () => {
return (
Expand Down Expand Up @@ -63,11 +65,37 @@ const Router = () => {
);
};

const FallbackRenderPage = ({ error, resetErrorBoundary }) => {
// Call resetErrorBoundary() to reset the error boundary and retry the render.
const navigate = useNavigate();
return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: 'red' }}>{error.message}</pre>
<button
onClick={() => {
resetErrorBoundary();
navigate('/');
}}
>
Return to home page.
</button>
</div>
);
};

const App = () => {
return (
<ThemeProvider theme={appTheme}>
<Router />
</ThemeProvider>
<ErrorBoundary
onReset={() => {
console.log('hi');
}}
fallbackRender={FallbackRenderPage}
>
<ThemeProvider theme={appTheme}>
<Router />
</ThemeProvider>
</ErrorBoundary>
);
};

Expand Down

0 comments on commit 271db3c

Please sign in to comment.