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

TASK: Add errorboundary and reporting #409

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
38 changes: 38 additions & 0 deletions src/components/atoms/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'

type Props = {
children: React.ReactNode
}

type State = {
hasError: boolean
error?: Error
}

class ErrorBoundary extends React.Component<Props, State> {
constructor(props: { children: React.ReactNode }) {
super(props)
this.state = {
hasError: false,
error: undefined,
}
}

static getDerivedStateFromError(error: Error) {
return { hasError: true, error }
}

// TODO
// * retrieve useful stacktrace (maybe read up here? https://www.loggly.com/blog/best-practices-for-client-side-logging-and-error-handling-in-react/)
// * add button to send error report to us
render() {
if (this.state.hasError) {
console.log({ error: this.state.error })
return <p>Error: {this.state.error?.message}</p>
}

return this.props.children
}
}

export default ErrorBoundary
5 changes: 4 additions & 1 deletion src/components/organisms/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'

import CircularProgress from '@material-ui/core/CircularProgress'

import ErrorBoundary from '../../atoms/ErrorBoundary'
import HeaderPlaceholder from './HeaderPlaceholder'
import Wrapper from './Wrapper'

Expand All @@ -14,7 +15,9 @@ type Props = {
const Content = ({ isLoading }: Props) => (
<Wrapper isLoading={isLoading}>
<HeaderPlaceholder />
{isLoading ? <CircularProgress /> : <Routing />}
<ErrorBoundary>
{isLoading ? <CircularProgress /> : <Routing />}
</ErrorBoundary>
</Wrapper>
)

Expand Down
2 changes: 0 additions & 2 deletions src/components/pages/TurnOrder/ModeSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const mapDispatchToProps = {

type Props = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {}

console.log(MODES)

const ModeSelection = ({ mode, setMode }: Props) => (
<Card>
<CardContent>
Expand Down