blob: 017265f48cb36bc4dead3b43f0b3f25d240be4e0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import React, {Component, ErrorInfo, ReactNode} from 'react'
import {ErrorScreen} from './error/ErrorScreen'
interface Props {
children?: ReactNode
}
interface State {
hasError: boolean
error: any
}
export class ErrorBoundary extends Component<Props, State> {
public state: State = {
hasError: false,
error: undefined,
}
public static getDerivedStateFromError(error: Error): State {
return {hasError: true, error}
}
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error('Uncaught error:', error, errorInfo)
}
public render() {
if (this.state.hasError) {
return (
<ErrorScreen
title="Oh no!"
message="There was an unexpected issue in the application. Please let us know if this happened to you!"
details={this.state.error.toString()}
/>
)
}
return this.props.children
}
}
|