aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/ErrorBoundary.tsx
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-06-24 13:29:50 +0200
committerAriel Costas Guerrero <ariel@costas.dev>2025-06-24 13:29:50 +0200
commit894e67863dbb89a4819e825fcdf7117021082b2a (patch)
treefb544ef7fa99ff86489717e793595f503783bb72 /src/frontend/app/ErrorBoundary.tsx
parent7dd9ea97a2f34a35e80c28d59d046f839eb6c60b (diff)
Replace leaflet for maplibre, use react-router in framework mode
Diffstat (limited to 'src/frontend/app/ErrorBoundary.tsx')
-rw-r--r--src/frontend/app/ErrorBoundary.tsx46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/frontend/app/ErrorBoundary.tsx b/src/frontend/app/ErrorBoundary.tsx
new file mode 100644
index 0000000..5c877b7
--- /dev/null
+++ b/src/frontend/app/ErrorBoundary.tsx
@@ -0,0 +1,46 @@
+import React, { Component, type ReactNode } from 'react';
+
+interface ErrorBoundaryProps {
+ children: ReactNode;
+}
+
+interface ErrorBoundaryState {
+ hasError: boolean;
+ error: Error | null;
+}
+
+class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
+ constructor(props: ErrorBoundaryProps) {
+ super(props);
+ this.state = {
+ hasError: false,
+ error: null
+ };
+ }
+
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState {
+ return {
+ hasError: true,
+ error
+ };
+ }
+
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
+ console.error("Uncaught error:", error, errorInfo);
+ }
+
+ render() {
+ if (this.state.hasError) {
+ return <>
+ <h1>Something went wrong.</h1>
+ <pre>
+ {this.state.error?.stack}
+ </pre>
+ </>;
+ }
+
+ return this.props.children;
+ }
+}
+
+export default ErrorBoundary;