-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(app): implement a global error boundary component #285
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.container { | ||
height: 100vh; | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.illustration-container { | ||
position: 'relative'; | ||
background: rgba(134, 101, 197, 0.2); | ||
width: 100%; | ||
height: 100%; | ||
margin-top: 24px; | ||
padding: 0px 3%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.illustration { | ||
position: relative; | ||
top: -15%; | ||
width: 50vh; | ||
} | ||
|
||
.error-message-container { | ||
height: 100vh; | ||
padding: 0px 2%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.error-message-container h1 { | ||
font-size: 4em; | ||
font-weight: bolder; | ||
color: rgba(0, 0, 0, 0.7); | ||
} | ||
|
||
.error-message-container h2 { | ||
text-align: center; | ||
font-size: 2em; | ||
margin-bottom: 12px; | ||
font-weight: bold; | ||
color: rgba(0, 0, 0, 0.55); | ||
margin-top: 12px; | ||
} | ||
|
||
.error-message-container p { | ||
text-align: center; | ||
color: rgba(0, 0, 0, 0.55); | ||
margin-bottom: 2rem; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import ErrorNotification from '../Notification'; | ||
import Button from '../Button'; | ||
import Illustration from '../../assets/img/error_boundary_ui.svg'; | ||
import './ErrorBoundary.css'; | ||
|
||
class ErrorBoundary extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { hasError: false, error: null, errorInfo: null }; | ||
} | ||
|
||
static getDerivedStateFromError(error) { | ||
// Update state so the next render will show the fallback UI. | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error, errorInfo) { | ||
// You can also log the error to an error reporting service | ||
//notifySlack(error, errorInfo) | ||
this.setState({ error, errorInfo }); | ||
} | ||
|
||
showNotifications = (error) => { | ||
this.setState((prev) => ({ | ||
errors: [...prev.errors, error], | ||
})); | ||
}; | ||
|
||
reload = () => { | ||
window.location.href = '/'; | ||
}; | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<> | ||
<ErrorNotification | ||
key={`notif-boundary`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does our eslint config allow for unnecessary string template? If so, I should change that. |
||
title="Error" | ||
message={this.state.error?.message || 'Something happened!'} | ||
position="top-right" | ||
variant="danger" | ||
closeable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
onClose={() => {}} | ||
/> | ||
<div className="container"> | ||
<div className="error-message-container"> | ||
<h1>400</h1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily a 400 error, could be a client-side error. |
||
<h2>{this.state.error?.message}</h2> | ||
<p>We are having an issue, please click on the button bellow to reload the page !</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please proofread. Idea: we should provide a link to https://github.com/FNNDSC/ChRIS_store_ui/issues |
||
|
||
<Button id="reload-error-btn" variant="primary" onClick={() => this.reload()}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It would be better to navigate "home". I got your comments |
||
<span>Retry</span> | ||
</Button> | ||
</div> | ||
<div className="illustration-container"> | ||
<img src={Illustration} alt="Error illustration" className="illustration" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did this illustration come from? Just want to make sure reuse is permitted. Or perhaps (in a future issue) we should loop back with @mairin and consider using "brainy" the mascot here (similar to the 404 error page). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The illustration come from undraw |
||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantic: don't assume web app is served from
/
, i.e. this will not work if deployed on a subpath (by settingPUBLIC_URL
orhomepage
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will do it then