|
|
@ -1,7 +1,9 @@
|
|
|
|
import React, { Component, ErrorInfo, ReactNode } from 'react';
|
|
|
|
import React, { Component, ErrorInfo, ReactNode } from 'react';
|
|
|
|
import ErrorPage from './ErrorPage';
|
|
|
|
import ErrorPage from './ErrorPage';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface ErrorBoundaryProps {
|
|
|
|
interface ErrorBoundaryProps {
|
|
|
|
|
|
|
|
fallback: (error: Error, errorInfo: ErrorInfo) => ReactNode;
|
|
|
|
children: ReactNode;
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -22,15 +24,12 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
|
|
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
|
|
|
// Vous pouvez également enregistrer l'erreur dans un service de journalisation
|
|
|
|
|
|
|
|
console.error('Error caught by ErrorBoundary:', error, errorInfo);
|
|
|
|
console.error('Error caught by ErrorBoundary:', error, errorInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render(): ReactNode {
|
|
|
|
render(): ReactNode {
|
|
|
|
if (this.state.hasError) {
|
|
|
|
if (this.state.hasError) {
|
|
|
|
// Vous pouvez personnaliser cette partie avec une page d'erreur
|
|
|
|
return this.props.fallback(new Error('Error caught by ErrorBoundary'), {});
|
|
|
|
//return <h1>Something went wrong. Please try again later.</h1>;
|
|
|
|
|
|
|
|
return <ErrorPage/>;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.props.children;
|
|
|
|
return this.props.children;
|
|
|
@ -40,6 +39,7 @@ class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
|
|
export default ErrorBoundary;
|
|
|
|
export default ErrorBoundary;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface ErrorBoundaryProps {
|
|
|
|
// interface ErrorBoundaryProps {
|
|
|
|
// children: ReactNode;
|
|
|
|
// children: ReactNode;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|