| 1 |
import React, { Component, Fragment } from 'react'; |
| 2 |
|
| 3 |
import '../../css/admin/shared/error-boundary.scss'; |
| 4 |
|
| 5 |
export default class ErrorBoundary extends Component { |
| 6 |
|
| 7 |
constructor(props) { |
| 8 |
super(props); |
| 9 |
|
| 10 |
this.state = { |
| 11 |
hasError: false, |
| 12 |
error: false, |
| 13 |
info: false, |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
componentDidCatch(error, info) { |
| 18 |
this.setState({ |
| 19 |
hasError: true, |
| 20 |
error, |
| 21 |
info, |
| 22 |
}); |
| 23 |
} |
| 24 |
|
| 25 |
render() { |
| 26 |
return ( |
| 27 |
<Fragment> |
| 28 |
{ |
| 29 |
this.state.hasError |
| 30 |
? |
| 31 |
<div className="wpupg-error-boundary"> |
| 32 |
<p> |
| 33 |
<strong>Something went wrong</strong><br/> |
| 34 |
Please contact <a href="mailto:support@bootstrapped.ventures">support@bootstrapped.ventures</a> and send along the following information:</p> |
| 35 |
<pre> |
| 36 |
{ this.props.module ? `Module: ${ this.props.module }\n` : null } |
| 37 |
{ this.state.error ? `Error: ${ this.state.error.toString() }\n` : null } |
| 38 |
{ this.state.info ? `Stack: ${ this.state.info.componentStack }` : null } |
| 39 |
</pre> |
| 40 |
</div> |
| 41 |
: |
| 42 |
this.props.children |
| 43 |
} |
| 44 |
</Fragment> |
| 45 |
); |
| 46 |
} |
| 47 |
} |
| 48 |
|