/* * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ import links from '../../links.json' import { Logger } from '../../utils/logger' import frontendVersion from '../../version.json' import { UiIcon } from '../common/icons/ui-icon' import { ExternalLink } from '../common/links/external-link' import type { ErrorInfo, PropsWithChildren, ReactNode } from 'react' import React, { Component } from 'react' import { Button, Container } from 'react-bootstrap' import { ArrowRepeat as IconArrowRepeat } from 'react-bootstrap-icons' const log = new Logger('ErrorBoundary') /** * An error boundary for the whole application. * The text in this is not translated, because the error could be part of the translation framework, * and we still want to display something to the user that's meaningful (and searchable). */ export class ErrorBoundary extends Component> { state: { hasError: boolean } constructor(props: Readonly) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(): { hasError: boolean } { // Update state so the next render will show the fallback UI. return { hasError: true } } componentDidCatch(error: Error, errorInfo: ErrorInfo): void { log.error('Error catched', error, errorInfo) } refreshPage(): void { window.location.reload() } render(): ReactNode | undefined { if (this.state.hasError) { return (

An unknown error occurred

Don't worry, this happens sometimes. If this is the first time you see this page then try reloading the app.

If you can reproduce this error, then we would be glad if you or
) } else { return this.props.children } } }