// This file is part of Moonfire NVR, a security camera network video recorder. // Copyright (C) 2021 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt. // SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception import Avatar from "@mui/material/Avatar"; import Container from "@mui/material/Container"; import BugReportIcon from "@mui/icons-material/BugReport"; import React from "react"; interface State { error: any; } interface Props { children: React.ReactNode; } /** * A simple error * boundary meant to go at the top level. * * The assumption is that any error here is a bug in the UI layer. Components * shouldn't throw errors upward even if there are network or server problems. * * Limitations: as described in the React docs, error boundaries don't catch * errors in async code / rejected Promises. */ class MoonfireErrorBoundary extends React.Component { constructor(props: Props) { super(props); this.state = { error: null }; } static getDerivedStateFromError(error: any) { return { error }; } componentDidCatch(error: any, errorInfo: React.ErrorInfo) { console.error("Uncaught error:", error, errorInfo); } render() { const { children } = this.props; if (this.state.error !== null) { var error; if (this.state.error.stack !== undefined) { error =
{this.state.error.stack}
; } else if (this.state.error instanceof Error) { error = ( <>
{this.state.error.name}
{this.state.error.message}
); } else { error =
{this.state.error}
; } return (

Error

Sorry! You've found a bug in Moonfire NVR. We need a good bug report to get it fixed. Can you help?

How to report a bug

Please open{" "} Moonfire NVR's issue tracker {" "} and see if this problem has already been reported.

Can't find anything?

Open a new issue with as much detail as you can:

Already reported?

The error

{error}
); } return children; } } export default MoonfireErrorBoundary;