import { ErrorMessage } from "@/components/layout/ErrorBoundary"; import { Link } from "@/components/text/Link"; import { conf } from "@/setup/config"; import { Component, ReactNode } from "react"; import { VideoPlayerHeader } from "./VideoPlayerHeader"; interface ErrorBoundaryState { hasError: boolean; error?: { name: string; description: string; path: string; }; } interface VideoErrorBoundaryProps { children?: ReactNode; title?: string; onGoBack?: () => void; } export class VideoErrorBoundary extends Component< VideoErrorBoundaryProps, ErrorBoundaryState > { constructor(props: VideoErrorBoundaryProps) { super(props); this.state = { hasError: false, }; } static getDerivedStateFromError() { return { hasError: true, }; } componentDidCatch(error: any, errorInfo: any) { console.error("Render error caught", error, errorInfo); if (error instanceof Error) { const realError: Error = error as Error; this.setState((s) => ({ ...s, hasError: true, error: { name: realError.name, description: realError.message, path: errorInfo.componentStack.split("\n")[1], }, })); } } render() { if (!this.state.hasError) return this.props.children; // TODO make responsive, needs to work in tiny player return (
The video player encounted a fatal error, please report it to the{" "} Discord server {" "} or on{" "} GitHub .
); } }