add errorboundary

This commit is contained in:
hyunwoo93.cha
2024-08-12 10:33:15 +09:00
parent bc4c77d23a
commit a76f6426c4
2 changed files with 49 additions and 8 deletions

View File

@@ -38,6 +38,7 @@ import { checkValidCountry } from "../lunaSend/common";
import { lunaTest } from "../lunaSend/lunaTest";
import * as Config from "../utils/Config";
import { $L, clearLaunchParams, getLaunchParams } from "../utils/helperMethods";
import ErrorBoundary from "../views/ErrorBoundary";
import MainView from "../views/MainView/MainView";
import css from "./App.module.less";
import { getMenuByLinkTpCd, handleDeepLink } from "./deepLinkHandler";
@@ -326,6 +327,7 @@ function AppBase(props) {
}, [dispatch]);
return (
<ErrorBoundary>
<MainView
className={
typeof window === "object" &&
@@ -334,6 +336,7 @@ function AppBase(props) {
css.preventMouse
}
/>
</ErrorBoundary>
);
}

View File

@@ -0,0 +1,38 @@
import React, { Component } from "react";
import { connect } from "react-redux";
import { clearLaunchParams } from "../utils/helperMethods";
class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
console.error("Uncaught error:", error, errorInfo);
}
componentDidUpdate(prevProps, prevState) {
if (this.state.hasError) {
clearLaunchParams();
if (typeof window === "object") {
window.location.reload();
}
}
}
render() {
if (this.state.hasError) {
return <div>Something went wrong.</div>;
}
return this.props.children;
}
}
export default connect()(ErrorBoundary);