Add a widget to present errors nicely.

master
Tom Hacohen 7 years ago
parent 8367767006
commit b0cae39814

@ -1,5 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import PrettyError from '../widgets/PrettyError';
class ErrorBoundary extends React.Component { class ErrorBoundary extends React.Component {
state: { state: {
error?: Error; error?: Error;
@ -17,17 +19,7 @@ class ErrorBoundary extends React.Component {
render() { render() {
if (this.state.error) { if (this.state.error) {
return ( return (
<div> <PrettyError error={this.state.error} />
<h2>Something went wrong!</h2>
<pre>
{this.state.error.message}
</pre>
<h3>Stack trace:</h3>
<pre>
{this.state.error.stack}
</pre>
</div>
); );
} }
return this.props.children; return this.props.children;

@ -0,0 +1,18 @@
import * as React from 'react';
import { pure } from 'recompose';
export const PrettyError = pure((props: any) => (
<div>
<h2>Something went wrong!</h2>
<pre>
{props.error.message}
</pre>
<h3>Stack trace:</h3>
<pre>
{props.error.stack}
</pre>
</div>
));
export default PrettyError;
Loading…
Cancel
Save