Skip to content
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/error boundary #3493

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react'
import { connect, ConnectedProps } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { bindActionCreators } from 'redux'

import { actions, selectors } from 'data'

import ErrorModal from './template'

class ErrorBoundary extends React.Component<Props, { error: null | TypeError }> {
constructor(props) {
super(props)
this.state = {
error: null
}
}

componentDidCatch(error) {
this.setState({
error
})
}

onSubmit = () => {
this.setState({ error: null })
if (this.props.isAuthenticated) {
this.props.history.push('/home')
} else {
this.props.history.push('/login')
window.location.reload(true)
}
}

render() {
if (this.state.error) {
return <ErrorModal error={this.state.error} onSubmit={this.onSubmit} />
}
return this.props.children
}
}

const mapStateToProps = (state) => ({
isAuthenticated: selectors.auth.isAuthenticated(state)
})

const mapDispatchToProps = (dispatch) => ({
authActions: bindActionCreators(actions.auth, dispatch),
routerActions: bindActionCreators(actions.router, dispatch)
})

const connector = connect(mapStateToProps, mapDispatchToProps)

type Props = ConnectedProps<typeof connector> & { history: { push: (path: string) => void } }

export default withRouter(connector(ErrorBoundary))
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const TitleGroup = styled(TextGroup)`
justify-content: center;
align-items: center;
`
const ErrorDetails = styled.details`
margin-top: 20px;
white-space: pre-wrap;
const ErrorDetails = styled.div`
margin-top: 8px;
white-space: pre-line;
max-height: 350px;
overflow: scroll;
::-webkit-scrollbar {
Expand All @@ -38,25 +38,15 @@ const ErrorDetails = styled.details`
}
`

const ErrorBoundary = props => {
const { error, errorInfo, onSubmit, position, total } = props
const ErrorBoundary = (props: { error: TypeError; onSubmit: any }) => {
const { error, onSubmit } = props

return (
<Modal
size='large'
style={{ zIndex: 999 }}
position={position}
total={total}
>
<Modal size='large' style={{ zIndex: 999 }}>
<ModalHeader closeButton={false}>
<TitleGroup inline>
<Icon name='alert-filled' size='28px' color='blue900' />
<Text
weight={400}
size={'22px'}
color='blue900'
style={{ paddingLeft: '8px' }}
>
<Text weight={400} size='22px' color='blue900' style={{ paddingLeft: '8px' }}>
<FormattedMessage
id='modal.errorboundary.title'
defaultMessage="Oops! Something's not right here"
Expand All @@ -66,20 +56,18 @@ const ErrorBoundary = props => {
</ModalHeader>
<ModalBody>
<TextGroup>
<Text weight={400} size={'14px'} color='grey700'>
<Text weight={400} size='14px' color='grey700'>
<FormattedMessage
id='modal.errorboundary.message'
defaultMessage="We're sorry, but it seems like something is not quite right. Please try again or contact support if the problem persists."
/>
</Text>
</TextGroup>
<Text weight={400} size={'14px'}>
<ErrorDetails>
<summary>Error Details</summary>
{error && error.toString()}
<br />
{errorInfo.componentStack}
</ErrorDetails>
<Text weight={600} size='16px' color='red600'>
Error Details:
</Text>
<Text weight={400} size='14px'>
<ErrorDetails>{error && error.stack}</ErrorDetails>
</Text>
</ModalBody>
<ModalFooter align='right'>
Expand Down