Add server-generated /config.js; add error boundary
This commit is contained in:
parent
04ee6b8be2
commit
840cb5b182
14 changed files with 184 additions and 85 deletions
32
web/src/components/ErrorBoundary.js
Normal file
32
web/src/components/ErrorBoundary.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import * as React from "react";
|
||||
|
||||
class ErrorBoundary extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { error: null, info: null };
|
||||
}
|
||||
|
||||
componentDidCatch(error, info) {
|
||||
this.setState({ error, info });
|
||||
console.error("[ErrorBoundary] A horrible error occurred", info);
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error) {
|
||||
return { error: true, errorMessage: error.toString() }
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.info) {
|
||||
return (
|
||||
<div>
|
||||
<h2>Something went wrong.</h2>
|
||||
<pre>{this.state.error && this.state.error.toString()}</pre>
|
||||
<pre>{this.state.info.componentStack}</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorBoundary;
|
Loading…
Add table
Add a link
Reference in a new issue