diff --git a/app/components/error.tsx b/app/components/error.tsx new file mode 100644 index 000000000..aa80939b6 --- /dev/null +++ b/app/components/error.tsx @@ -0,0 +1,47 @@ +import React from "react"; +import { IconButton } from "./button"; +import GithubIcon from "../icons/github.svg"; +import { ISSUE_URL } from "../constant"; + +interface IErrorBoundaryState { + hasError: boolean; + error: Error | null; + info: React.ErrorInfo | null; +} + +export class ErrorBoundary extends React.Component { + constructor(props: any) { + super(props); + this.state = { hasError: false, error: null, info: null }; + } + + componentDidCatch(error: Error, info: React.ErrorInfo) { + // Update state with error details + this.setState({ hasError: true, error, info }); + } + + render() { + if (this.state.hasError) { + // Render error message + return ( +
+

Oops, something went wrong!

+
+            {this.state.error?.toString()}
+            {this.state.info?.componentStack}
+          
+ + + } + bordered + /> + +
+ ); + } + // if no error occurred, render children + return this.props.children; + } +}