From 693553213027cb3139fd0319479ce2662214f451 Mon Sep 17 00:00:00 2001 From: SelfMadeSystem Date: Thu, 7 Mar 2024 17:19:32 -0500 Subject: [PATCH 1/3] Improve ErrorBoundary component to better display errors --- src/lib/ui/components/ErrorBoundary.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib/ui/components/ErrorBoundary.tsx b/src/lib/ui/components/ErrorBoundary.tsx index e55a40c..debda61 100644 --- a/src/lib/ui/components/ErrorBoundary.tsx +++ b/src/lib/ui/components/ErrorBoundary.tsx @@ -6,10 +6,12 @@ import { FormText } from "@ui/components/discord/Forms"; import { createThemedStyleSheet } from "@ui/styles"; import { ScrollView } from "react-native"; -interface ErrorBoundaryState { - hasErr: boolean; - errText?: string; -} +type ErrorBoundaryState = { + hasErr: false; +} | { + hasErr: true; + error: Error; +}; export interface ErrorBoundaryProps { children: JSX.Element | JSX.Element[]; @@ -34,7 +36,7 @@ export default class ErrorBoundary extends React.Component ({ hasErr: true, errText: error.message }); + static getDerivedStateFromError = (error: Error) => ({ hasErr: true, error }); render() { if (!this.state.hasErr) return this.props.children; @@ -42,12 +44,16 @@ export default class ErrorBoundary extends React.Component {Strings.UH_OH} - {this.state.errText} + {this.state.error.name} + {this.state.error.message} + {this.state.error.stack && + {this.state.error.stack} + }