mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
* automate feature * Moved all providers to app level to simplify homepage * Circular dependency fixes * You will see that now toolRegistry gets a tool config and a tool settings object. These enable automate to run the tools using as much static code as possible. --------- Co-authored-by: Connor Yoh <connor@stirlingpdf.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import React from 'react';
|
|
import { Text, Button, Stack } from '@mantine/core';
|
|
|
|
interface ErrorBoundaryState {
|
|
hasError: boolean;
|
|
error?: Error;
|
|
}
|
|
|
|
interface ErrorBoundaryProps {
|
|
children: React.ReactNode;
|
|
fallback?: React.ComponentType<{error?: Error; retry: () => void}>;
|
|
}
|
|
|
|
export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
constructor(props: ErrorBoundaryProps) {
|
|
super(props);
|
|
this.state = { hasError: false };
|
|
}
|
|
|
|
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
return { hasError: true, error };
|
|
}
|
|
|
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
console.error('ErrorBoundary caught an error:', error, errorInfo);
|
|
}
|
|
|
|
retry = () => {
|
|
this.setState({ hasError: false, error: undefined });
|
|
};
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
if (this.props.fallback) {
|
|
const Fallback = this.props.fallback;
|
|
return <Fallback error={this.state.error} retry={this.retry} />;
|
|
}
|
|
|
|
return (
|
|
<Stack align="center" justify="center" style={{ minHeight: '200px', padding: '2rem' }}>
|
|
<Text size="lg" fw={500} c="red">Something went wrong</Text>
|
|
{process.env.NODE_ENV === 'development' && this.state.error && (
|
|
<Text size="sm" c="dimmed" style={{ textAlign: 'center', fontFamily: 'monospace' }}>
|
|
{this.state.error.message}
|
|
</Text>
|
|
)}
|
|
<Button onClick={this.retry} variant="light">
|
|
Try Again
|
|
</Button>
|
|
</Stack>
|
|
);
|
|
}
|
|
|
|
return this.props.children;
|
|
}
|
|
} |