Skip to content

Feature/solution actions #38

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

Merged
merged 6 commits into from
Sep 29, 2019
Prev Previous commit
Next Next commit
add ui error boundary
  • Loading branch information
ShMcK committed Sep 29, 2019
commit 139eafb60d71fc4d53781fdee612ee772dc822e4
9 changes: 6 additions & 3 deletions web-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as React from 'react'
import { ApolloProvider } from '@apollo/react-hooks'

import ErrorBoundary from './components/ErrorBoundary'
import client from './services/apollo'
import Routes from './Routes'

const App = () => (
<ApolloProvider client={client}>
<Routes />
</ApolloProvider>
<ErrorBoundary>
<ApolloProvider client={client}>
<Routes />
</ApolloProvider>
</ErrorBoundary>
)

export default App
23 changes: 23 additions & 0 deletions web-app/src/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react'

class ErrorBoundary extends React.Component {
public state = { hasError: false }

public componentDidCatch(error: Error, info: any) {
// Display fallback UI
this.setState({ hasError: true })
// You can also log the error to an error reporting service
console.error(error)
console.log(info)
}

public render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <h1>Something went wrong.</h1>
}
return this.props.children
}
}

export default ErrorBoundary