mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
Add error boundary to App
Catch errors in the component stack that reaches the App component and display an error message for them instead of a black screen.
This commit is contained in:
1 parent
a8e1971483
commit
b70303c437
1 file changed
+22
-8
@@ -5,13 +5,25 @@ import { BrowserRouter } from "react-router-dom";
|
|||||||
import { logger } from "@clusterio/lib/logging";
|
import { logger } from "@clusterio/lib/logging";
|
||||||
|
|
||||||
import basename from "../basename";
|
import basename from "../basename";
|
||||||
|
import ErrorBoundary from "./ErrorBoundary";
|
||||||
import SiteLayout from "./SiteLayout";
|
import SiteLayout from "./SiteLayout";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import PluginsContext from "./PluginsContext";
|
import PluginsContext from "./PluginsContext";
|
||||||
import LoginForm from "./LoginForm";
|
import LoginForm from "./LoginForm";
|
||||||
|
|
||||||
import { Card, Spin } from "antd";
|
import { Card, Spin, Typography } from "antd";
|
||||||
|
|
||||||
|
const { Paragraph } = Typography;
|
||||||
|
|
||||||
|
|
||||||
|
function ErrorCard(props) {
|
||||||
|
return <div className="login-container">
|
||||||
|
<Card>
|
||||||
|
<h1>An unexpected error occured</h1>
|
||||||
|
<Paragraph code className="error-traceback">{props.error.stack}</Paragraph>
|
||||||
|
</Card>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
|
||||||
export default function App(props) {
|
export default function App(props) {
|
||||||
let [connected, setConnected] = useState(false);
|
let [connected, setConnected] = useState(false);
|
||||||
@@ -77,12 +89,14 @@ export default function App(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ControlContext.Provider value={props.control}>
|
<ErrorBoundary Component={ErrorCard}>
|
||||||
<PluginsContext.Provider value={props.plugins}>
|
<ControlContext.Provider value={props.control}>
|
||||||
<BrowserRouter basename={basename}>
|
<PluginsContext.Provider value={props.plugins}>
|
||||||
{page}
|
<BrowserRouter basename={basename}>
|
||||||
</BrowserRouter>
|
{page}
|
||||||
</PluginsContext.Provider>
|
</BrowserRouter>
|
||||||
</ControlContext.Provider>
|
</PluginsContext.Provider>
|
||||||
|
</ControlContext.Provider>
|
||||||
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user