From c5c4b64ce2fe5bbd8d608d7dd8a4025d793dbc08 Mon Sep 17 00:00:00 2001 From: Giovanni Fossati Date: Wed, 18 Dec 2024 18:24:27 -0300 Subject: [PATCH] refactor(errorBoundary): return error and errorInfo object with the onError component --- .../src/AppInsightsErrorBoundary.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/applicationinsights-react-js/src/AppInsightsErrorBoundary.tsx b/applicationinsights-react-js/src/AppInsightsErrorBoundary.tsx index 2645968..856b032 100644 --- a/applicationinsights-react-js/src/AppInsightsErrorBoundary.tsx +++ b/applicationinsights-react-js/src/AppInsightsErrorBoundary.tsx @@ -13,13 +13,19 @@ export interface IAppInsightsErrorBoundaryProps { export interface IAppInsightsErrorBoundaryState { hasError: boolean + error: Error | null; + errorInfo: React.ErrorInfo | null; } export default class AppInsightsErrorBoundary extends React.Component { - state = { hasError: false }; + state: IAppInsightsErrorBoundaryState = { + hasError: false, + error: null, + errorInfo: null, + }; componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { - this.setState({ hasError: true }); + this.setState({ hasError: true, error, errorInfo }); this.props.appInsights.trackException({ error: error, exception: error, @@ -29,11 +35,14 @@ export default class AppInsightsErrorBoundary extends React.Component