import { Component } from "react"; import { Trans, useTranslation } from "react-i18next"; import { IconPatch } from "@/components/buttons/IconPatch"; import { Icons } from "@/components/Icon"; import { Link } from "@/components/text/Link"; import { Title } from "@/components/text/Title"; import { conf } from "@/setup/config"; interface ErrorShowcaseProps { error: { name: string; description: string; path: string; }; } export function ErrorShowcase(props: ErrorShowcaseProps) { return (

{props.error.name} - {props.error.description}

{props.error.path}

); } interface ErrorMessageProps { error?: { name: string; description: string; path: string; }; localSize?: boolean; children?: React.ReactNode; } export function ErrorMessage(props: ErrorMessageProps) { const { t } = useTranslation(); return (
{t("media.errors.genericTitle")} {props.children ? (

{props.children}

) : (

)}
{props.error ? : null}
); } interface ErrorBoundaryState { hasError: boolean; error?: { name: string; description: string; path: string; }; } export class ErrorBoundary extends Component< Record, ErrorBoundaryState > { constructor(props: { children: any }) { 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 as any; return ; } }