ajout de l'error handeling (non finis) et rediretion vers une page d'erreur en cas de page not found 🐛:
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
7c8a5d1f4a
commit
e45fe3e7ca
@ -0,0 +1,67 @@
|
||||
import React, { Component, ErrorInfo, ReactNode } from 'react';
|
||||
import ErrorPage from './ErrorPage';
|
||||
|
||||
interface ErrorBoundaryProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
interface ErrorBoundaryState {
|
||||
hasError: boolean;
|
||||
}
|
||||
|
||||
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
constructor(props: ErrorBoundaryProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
hasError: false,
|
||||
};
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(): ErrorBoundaryState {
|
||||
return { hasError: true };
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
render(): ReactNode {
|
||||
if (this.state.hasError) {
|
||||
// Vous pouvez personnaliser cette partie avec une page d'erreur
|
||||
//return <h1>Something went wrong. Please try again later.</h1>;
|
||||
return <ErrorPage/>;
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default ErrorBoundary;
|
||||
|
||||
|
||||
// interface ErrorBoundaryProps {
|
||||
// children: ReactNode;
|
||||
// }
|
||||
|
||||
|
||||
// class ErrorBoundary extends React.Component <ErrorBoundaryProps>{
|
||||
// state = { hasError : true }
|
||||
// //@ts-ignore
|
||||
// static getDerivedStateFromError(error){
|
||||
// return { hasError : true};
|
||||
// }
|
||||
|
||||
// componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
|
||||
// console.log(error, errorInfo);
|
||||
// }
|
||||
|
||||
// render(){
|
||||
// if (this.state.hasError){
|
||||
// return <ErrorPage/>;
|
||||
// }
|
||||
// return this.props.children;
|
||||
// }
|
||||
// }
|
||||
|
||||
// export default ErrorBoundary;
|
@ -0,0 +1,28 @@
|
||||
|
||||
import React from 'react';
|
||||
import { useTheme } from '../Style/ThemeContext';
|
||||
import { Link } from 'react-router-dom';
|
||||
import './ErrorStyle.css';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
|
||||
|
||||
//@ts-ignore
|
||||
function ErrorPage({ msg = "Something is really wrong"}) {
|
||||
|
||||
const theme = useTheme();
|
||||
|
||||
// const mystyle = {
|
||||
// backgroundColor: "#0064E0",
|
||||
// };
|
||||
|
||||
return (
|
||||
<div className='mainErrorDiv'>
|
||||
<div className='titleError'>
|
||||
<h1>{msg}</h1>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ErrorPage;
|
@ -0,0 +1,15 @@
|
||||
|
||||
.mainErrorDiv{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
.titleError{
|
||||
border: solid 2px #C70039;
|
||||
border-radius: 10px;
|
||||
margin: 15px;
|
||||
padding: 10px;
|
||||
box-shadow: 5px 5px 5px #900C3F;
|
||||
}
|
Loading…
Reference in new issue