diff --git a/app/demo/error-boundary/page.tsx b/app/demo/error-boundary/page.tsx
new file mode 100644
index 0000000..13901a0
--- /dev/null
+++ b/app/demo/error-boundary/page.tsx
@@ -0,0 +1,318 @@
+"use client";
+
+import { useState } from "react";
+import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import { ErrorBoundary, withErrorBoundary } from "@/components/error-boundary";
+import { AppError, ErrorCode } from "@/types/errors";
+
+// Component that throws an error when triggered
+function ErrorThrower({
+ shouldThrow = false,
+ errorType = "generic",
+}: {
+ shouldThrow?: boolean;
+ errorType?: string;
+}) {
+ if (shouldThrow) {
+ switch (errorType) {
+ case "app-error":
+ throw new AppError(
+ ErrorCode.DECRYPTION_FAILED,
+ 400,
+ "This is a custom app error for testing"
+ );
+ case "chunk-error":
+ const chunkError = new Error("Loading chunk 123 failed");
+ chunkError.name = "ChunkLoadError";
+ throw chunkError;
+ case "network-error":
+ throw new Error("Network request failed");
+ case "generic":
+ default:
+ throw new Error("This is a generic test error");
+ }
+ }
+ return (
+
✅ Component is working fine!
+ );
+}
+
+// Component wrapped with HOC
+const WrappedErrorThrower = withErrorBoundary(ErrorThrower, {
+ showReset: true,
+ showHome: false,
+});
+
+export default function ErrorBoundaryDemo() {
+ const [globalError, setGlobalError] = useState(false);
+ const [globalErrorType, setGlobalErrorType] = useState("generic");
+ const [localError, setLocalError] = useState(false);
+ const [localErrorType, setLocalErrorType] = useState("generic");
+ const [hocError, setHocError] = useState(false);
+ const [hocErrorType, setHocErrorType] = useState("generic");
+
+ const handleCustomFallback = (error: Error) => (
+
+
+ Custom Error Handler
+
+
+ Caught: {error.message}
+
+
+ );
+
+ const errorTypes = [
+ { value: "generic", label: "Generic Error" },
+ { value: "app-error", label: "App Error (with code)" },
+ { value: "chunk-error", label: "Chunk Load Error" },
+ { value: "network-error", label: "Network Error" },
+ ];
+
+ return (
+
+
+
+
+ ErrorBoundary Demo
+
+
+ Demo of the ErrorBoundary component with different error scenarios
+ and configurations.
+
+
+
+
+ {/* Global Error Boundary Test */}
+
+
+ Global Error Boundary
+
+ Test the app-level error boundary that catches all unhandled
+ errors.
+
+
+
+
+ Error Type:
+ setGlobalErrorType(e.target.value)}
+ className="border-input bg-background w-full rounded-md border px-3 py-2 text-sm"
+ >
+ {errorTypes.map((type) => (
+
+ {type.label}
+
+ ))}
+
+
+
+ setGlobalError(true)}
+ variant="destructive"
+ className="w-full"
+ >
+ Trigger Global Error
+
+
+
+
+
+
+
+
+ {/* Local Error Boundary Test */}
+
+
+ Local Error Boundary
+
+ Test a local error boundary that only catches errors in a
+ specific component tree.
+
+
+
+
+ Error Type:
+ setLocalErrorType(e.target.value)}
+ className="border-input bg-background w-full rounded-md border px-3 py-2 text-sm"
+ >
+ {errorTypes.map((type) => (
+
+ {type.label}
+
+ ))}
+
+
+
+ setLocalError(true)}
+ variant="destructive"
+ className="w-full"
+ >
+ Trigger Local Error
+
+
+
+
+
+
+
+
+
+
+ {/* Custom Fallback Test */}
+
+
+ Custom Fallback UI
+
+ Test error boundary with a custom fallback component instead of
+ the default UI.
+
+
+
+ setHocError(true)}
+ variant="destructive"
+ className="w-full"
+ >
+ Trigger Custom Fallback
+
+
+
+
+
+
+
+
+
+
+ {/* HOC Error Boundary Test */}
+
+
+ HOC Error Boundary
+
+ Test the withErrorBoundary higher-order component wrapper.
+
+
+
+
+ Error Type:
+ setHocErrorType(e.target.value)}
+ className="border-input bg-background w-full rounded-md border px-3 py-2 text-sm"
+ >
+ {errorTypes.map((type) => (
+
+ {type.label}
+
+ ))}
+
+
+
+ setHocError(true)}
+ variant="destructive"
+ className="w-full"
+ >
+ Trigger HOC Error
+
+
+
+
+
+
+
+
+
+
+
Features Demonstrated
+
+
+
✅ Error Handling Features
+
+ • React Error Boundary implementation
+ • Integration with app error system
+ • Custom error message formatting
+ • Error logging to console and logger
+ • Recovery actions (reset, go home)
+ • Development vs production error details
+
+
+
+
🎨 UI Features
+
+ • Consistent with shadcn/ui design system
+ • Dark/light theme support
+ • Mobile-responsive layout
+ • Accessibility support (ARIA, keyboard nav)
+ • Custom fallback component support
+ • Higher-order component wrapper
+
+
+
+
+
+
+
Error Types
+
+
+
🔴 Error Categories
+
+
+ • Generic: Standard JavaScript errors
+
+
+ • App Error: Custom errors with error codes
+
+
+ • Chunk Load: Application resource loading
+ failures
+
+
+ • Network: Network connectivity issues
+
+
+
+
+
🛠️ Recovery Actions
+
+
+ • Try Again: Resets error boundary state
+
+
+ • Go Home: Navigates to homepage
+
+
+ • Custom Fallback: Alternative error UI
+
+
+ • Error Logging: Automatic error reporting
+
+
+
+
+
+
+
+ );
+}
diff --git a/app/layout.tsx b/app/layout.tsx
index ec259b2..590c04f 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import { ThemeProvider } from "@/components/theme-provider";
import { Header } from "@/components/header";
+import { ErrorBoundary } from "@/components/error-boundary";
import "./globals.css";
const geistSans = Geist({
@@ -36,10 +37,12 @@ export default function RootLayout({
enableSystem
disableTransitionOnChange
>
-
-
- {children}
-
+
+
+
+ {children}
+
+