/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./error-boundary.scss"; import type { ErrorInfo } from "react"; import React from "react"; import { observer } from "mobx-react"; import { Button } from "../button"; import { navigation } from "../../navigation"; import { issuesTrackerUrl, slackUrl } from "../../../common/vars"; import type { SingleOrMany } from "../../utils"; export interface ErrorBoundaryProps { children?: SingleOrMany; } interface State { error?: Error; errorInfo?: ErrorInfo; } @observer export class ErrorBoundary extends React.Component { public state: State = {}; componentDidCatch(error: Error, errorInfo: ErrorInfo) { this.setState({ error, errorInfo }); } back = () => { this.setState({ error: undefined, errorInfo: undefined }); navigation.goBack(); }; render() { const { error, errorInfo } = this.state; if (error) { return (
{"App crash at "} {location.pathname}

{"To help us improve the product please report bugs to "} Slack {" community or "} Github {" issues tracker."}

Component stack:

{errorInfo?.componentStack}

Error stack:

{error.stack}
); } return this.props.children; } }