| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { Component } from 'react'; |
| import SchemaErrorFallback from './SchemaErrorFallback'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export default class ErrorBoundary extends Component { |
| constructor(props) { |
| super(props); |
| this.state = { hasError: false, error: null }; |
| } |
|
|
| static getDerivedStateFromError(error) { |
| return { hasError: true, error }; |
| } |
|
|
| componentDidCatch(error, info) { |
| |
| console.error('[ErrorBoundary] Caught error:', error); |
| if (info?.componentStack) { |
| console.error('[ErrorBoundary] Component stack:', info.componentStack); |
| } |
| |
| if (this.props.onError) { |
| this.props.onError(error, info); |
| } |
| } |
|
|
| handleRetry = () => { |
| this.setState({ hasError: false, error: null }); |
| }; |
|
|
| render() { |
| if (this.state.hasError) { |
| |
| if (this.props.fallback) { |
| return typeof this.props.fallback === 'function' |
| ? this.props.fallback({ |
| error: this.state.error, |
| retry: this.handleRetry, |
| }) |
| : this.props.fallback; |
| } |
|
|
| |
| return ( |
| <SchemaErrorFallback |
| error={this.state.error} |
| onRetry={this.handleRetry} |
| disease={this.props.disease} |
| /> |
| ); |
| } |
|
|
| return this.props.children; |
| } |
| } |
|
|
| |
| |
| |
| |
| export function SchemaErrorBoundary({ children, disease }) { |
| return ( |
| <ErrorBoundary |
| disease={disease} |
| fallback={({ error, retry }) => ( |
| <SchemaErrorFallback |
| error={error} |
| onRetry={retry} |
| disease={disease} |
| /> |
| )} |
| > |
| {children} |
| </ErrorBoundary> |
| ); |
| } |
|
|
|
|