@heritsilavo/react-error-boundary 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/next/ErrorBoundary.d.ts +3 -4
- package/dist/next/ErrorContext.d.ts +1 -0
- package/dist/next/index.js +36 -4269
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +29 -4262
- package/dist/next/index.mjs.map +1 -1
- package/dist/react/ErrorBoundary.d.ts +5 -0
- package/dist/react/{react/ErrorContext.d.ts → ErrorContext.d.ts} +1 -0
- package/dist/react/index.js +35 -35
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +36 -36
- package/dist/react/index.mjs.map +1 -1
- package/package.json +13 -6
- package/dist/react/next/ErrorBoundary.d.ts +0 -6
- package/dist/react/next/ErrorContext.d.ts +0 -19
- package/dist/react/react/CustomError.d.ts +0 -5
- package/dist/react/react/ErrorBoundary.d.ts +0 -6
- package/dist/react/react/components/DefaultErrorComponents.d.ts +0 -42
- package/dist/react/react/index.d.ts +0 -4
- /package/dist/react/{next/CustomError.d.ts → CustomError.d.ts} +0 -0
- /package/dist/react/{next/components → components}/DefaultErrorComponents.d.ts +0 -0
- /package/dist/react/{next/index.d.ts → index.d.ts} +0 -0
package/dist/react/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useState, useRef, useCallback, useEffect, createContext, useContext
|
1
|
+
import React, { Component, useState, useRef, useCallback, useEffect, createContext, useContext } from 'react';
|
2
2
|
|
3
3
|
class CustomError extends Error {
|
4
4
|
constructor(code, message, description) {
|
@@ -9,6 +9,34 @@ class CustomError extends Error {
|
|
9
9
|
}
|
10
10
|
}
|
11
11
|
|
12
|
+
// Composant de classe qui capture les erreurs React
|
13
|
+
class ErrorBoundaryComponent extends Component {
|
14
|
+
constructor(props) {
|
15
|
+
super(props);
|
16
|
+
this.state = { hasError: false };
|
17
|
+
}
|
18
|
+
// Appelé quand une erreur est détectée dans un composant enfant
|
19
|
+
static getDerivedStateFromError(error) {
|
20
|
+
return { hasError: true };
|
21
|
+
}
|
22
|
+
// Permet de logger l'erreur et d'exécuter du code de récupération
|
23
|
+
componentDidCatch(error, errorInfo) {
|
24
|
+
if (this.props.handleError) {
|
25
|
+
this.props.handleError(error);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
render() {
|
29
|
+
if (this.state.hasError) {
|
30
|
+
this.setState({ hasError: false });
|
31
|
+
return this.props.children;
|
32
|
+
}
|
33
|
+
return this.props.children;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
const ErrorBoundary = ({ children, handleError }) => {
|
37
|
+
return React.createElement(ErrorBoundaryComponent, { handleError: handleError }, children);
|
38
|
+
};
|
39
|
+
|
12
40
|
var util;
|
13
41
|
(function (util) {
|
14
42
|
util.assertEqual = (val) => val;
|
@@ -4334,7 +4362,7 @@ const ErrorContext = createContext({
|
|
4334
4362
|
error: null,
|
4335
4363
|
clearError: () => { }
|
4336
4364
|
});
|
4337
|
-
const ErrorProvider = ({ children, ErrorComponent = DefaultErrorComponent, autoHideDelay = 5000, onError = () => { }, closeErrorComponetOnClick = false }) => {
|
4365
|
+
const ErrorProvider = ({ children, ErrorComponent = DefaultErrorComponent, autoHideDelay = 5000, onError = () => { }, closeErrorComponetOnClick = false, handleError: externalHandleError }) => {
|
4338
4366
|
const [error, setError] = useState(null);
|
4339
4367
|
const timeoutRef = useRef(null);
|
4340
4368
|
// Fonction de nettoyage du timeout
|
@@ -4355,10 +4383,14 @@ const ErrorProvider = ({ children, ErrorComponent = DefaultErrorComponent, autoH
|
|
4355
4383
|
? error
|
4356
4384
|
: new CustomError('UNKNOWN_ERROR', 'Une erreur inattendue est survenue', error.message);
|
4357
4385
|
setError(newError);
|
4386
|
+
// Appel du gestionnaire d'erreurs externe s'il est fourni
|
4387
|
+
if (externalHandleError) {
|
4388
|
+
externalHandleError(newError);
|
4389
|
+
}
|
4358
4390
|
if (autoHideDelay > 0) {
|
4359
4391
|
timeoutRef.current = setTimeout(() => setError(null), autoHideDelay);
|
4360
4392
|
}
|
4361
|
-
}, [autoHideDelay]);
|
4393
|
+
}, [autoHideDelay, externalHandleError, onError]);
|
4362
4394
|
const clearError = React.useCallback(() => {
|
4363
4395
|
clearTimeout();
|
4364
4396
|
setError(null);
|
@@ -4369,7 +4401,7 @@ const ErrorProvider = ({ children, ErrorComponent = DefaultErrorComponent, autoH
|
|
4369
4401
|
clearError
|
4370
4402
|
}), [handleError, error, clearError]);
|
4371
4403
|
return (React.createElement(ErrorContext.Provider, { value: contextValue },
|
4372
|
-
React.createElement(ErrorBoundary,
|
4404
|
+
React.createElement(ErrorBoundary, { handleError: handleError },
|
4373
4405
|
error && (React.createElement(ErrorComponent, { error: error, onClose: clearError, closeOnClick: closeErrorComponetOnClick, visiblityTime: autoHideDelay })),
|
4374
4406
|
children)));
|
4375
4407
|
};
|
@@ -4389,37 +4421,5 @@ const useThrowError = () => {
|
|
4389
4421
|
}, [handleError]);
|
4390
4422
|
};
|
4391
4423
|
|
4392
|
-
// Composant de classe qui capture les erreurs React
|
4393
|
-
class ErrorBoundaryComponent extends Component {
|
4394
|
-
constructor(props) {
|
4395
|
-
super(props);
|
4396
|
-
this.state = { hasError: false };
|
4397
|
-
}
|
4398
|
-
// Appelé quand une erreur est détectée dans un composant enfant
|
4399
|
-
static getDerivedStateFromError(error) {
|
4400
|
-
return { hasError: true };
|
4401
|
-
}
|
4402
|
-
// Permet de logger l'erreur et d'exécuter du code de récupération
|
4403
|
-
componentDidCatch(error, errorInfo) {
|
4404
|
-
if (this.props.handleError) {
|
4405
|
-
this.props.handleError(error);
|
4406
|
-
}
|
4407
|
-
}
|
4408
|
-
render() {
|
4409
|
-
if (this.state.hasError) {
|
4410
|
-
this.setState({ hasError: false });
|
4411
|
-
return this.props.children;
|
4412
|
-
}
|
4413
|
-
return this.props.children;
|
4414
|
-
}
|
4415
|
-
}
|
4416
|
-
const ErrorBoundary = ({ children }) => {
|
4417
|
-
const { handleError } = useError();
|
4418
|
-
return React.createElement(ErrorBoundaryComponent, { handleError: handleError },
|
4419
|
-
" ",
|
4420
|
-
children,
|
4421
|
-
" ");
|
4422
|
-
};
|
4423
|
-
|
4424
4424
|
export { CustomError, DefaultErrorComponent, ErrorBoundary, ErrorProvider, useError, useThrowError };
|
4425
4425
|
//# sourceMappingURL=index.mjs.map
|