Skip to content

Commit

Permalink
feat: add error boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed May 15, 2023
1 parent c2b3966 commit 203515f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"query-string": "^8.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.4",
"react-fast-compare": "^3.2.1",
"reactstrap": "^9.1.8"
},
Expand Down
43 changes: 42 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
import '@arcgis/core/assets/esri/themes/light/main.css';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/js/dist/collapse';
import PropTypes from 'prop-types';
import { createRoot } from 'react-dom/client';
import { ErrorBoundary } from 'react-error-boundary';
import App from './App';

function ErrorFallback({ error }) {
return (
<div className="w-100 h-100 d-flex justify-content-center align-items-center">
<div className="alert alert-danger w-75" role="alert">
There was an error with the application!
<hr />
<div className="d-flex justify-content-between align-items-center w-100">
<button className="btn btn-primary" type="button" onClick={() => window.location.reload()}>
Reload
</button>
<button
className="btn btn-secondary"
type="button"
data-bs-toggle="collapse"
data-bs-target="#details"
aria-expanded="false"
aria-controls="technical details"
>
Show technical details 🤓
</button>
</div>
<div className="collapse mt-3" id="details">
<div className="card card-body">
<pre>{error?.stack}</pre>
</div>
</div>
</div>
</div>
);
}

ErrorFallback.propTypes = {
error: PropTypes.object,
};

document.title = import.meta.env.VITE_APP_TITLE;
createRoot(document.getElementById('root')).render(<App />);
createRoot(document.getElementById('root')).render(
<ErrorBoundary FallbackComponent={ErrorFallback}>
<App />
</ErrorBoundary>
);

0 comments on commit 203515f

Please sign in to comment.