|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { ErrorTestSuite } from '@/components/error/ErrorTestSuite'; |
| 4 | +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; |
| 5 | +import { EnhancedErrorBoundary, ErrorBoundaryPresets } from '@/components/error/EnhancedErrorBoundary'; |
| 6 | +import { Button } from '@/components/ui/button'; |
| 7 | +import { ErrorCategory } from '@/types/errors'; |
| 8 | +import { WalletConnector } from '@/components/WalletConnector'; |
| 9 | +import { LanguageSwitcher } from '@/components/LanguageSwitcher'; |
| 10 | + |
| 11 | +function ErrorDemo() { |
| 12 | + return ( |
| 13 | + <div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800"> |
| 14 | + <header className="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700"> |
| 15 | + <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> |
| 16 | + <div className="flex justify-between items-center h-16"> |
| 17 | + <div className="flex items-center gap-3"> |
| 18 | + <div className="w-8 h-8 bg-blue-600 rounded-lg flex items-center justify-center"> |
| 19 | + <span className="text-white font-bold text-sm">PC</span> |
| 20 | + </div> |
| 21 | + <h1 className="text-xl font-bold text-gray-900 dark:text-white"> |
| 22 | + Error Boundary Demo |
| 23 | + </h1> |
| 24 | + </div> |
| 25 | + <div className="flex items-center gap-3"> |
| 26 | + <LanguageSwitcher /> |
| 27 | + <WalletConnector /> |
| 28 | + </div> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + </header> |
| 32 | + |
| 33 | + <main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12"> |
| 34 | + <div className="text-center mb-12"> |
| 35 | + <h2 className="text-4xl font-bold text-gray-900 dark:text-white mb-4"> |
| 36 | + Error Handling Demonstration |
| 37 | + </h2> |
| 38 | + <p className="text-lg text-gray-600 dark:text-gray-300 max-w-2xl mx-auto"> |
| 39 | + Test comprehensive error boundaries with contextual error handling and recovery strategies |
| 40 | + </p> |
| 41 | + </div> |
| 42 | + |
| 43 | + {/* Error Test Suite */} |
| 44 | + <ErrorTestSuite /> |
| 45 | + |
| 46 | + {/* Individual Error Boundary Examples */} |
| 47 | + <div className="mt-16 space-y-12"> |
| 48 | + <div> |
| 49 | + <h3 className="text-2xl font-bold text-gray-900 dark:text-white mb-6"> |
| 50 | + Individual Error Boundary Examples |
| 51 | + </h3> |
| 52 | + |
| 53 | + <div className="grid grid-cols-1 lg:grid-cols-2 gap-8"> |
| 54 | + {/* Web3 Error Boundary */} |
| 55 | + <Card> |
| 56 | + <CardHeader> |
| 57 | + <CardTitle>Web3 Error Boundary</CardTitle> |
| 58 | + </CardHeader> |
| 59 | + <CardContent> |
| 60 | + <p className="text-gray-600 dark:text-gray-300 mb-4"> |
| 61 | + Handles blockchain-related errors with wallet reconnection options. |
| 62 | + </p> |
| 63 | + <ErrorBoundaryPresets.web3 enableRetry maxRetries={3}> |
| 64 | + <Button |
| 65 | + onClick={() => { |
| 66 | + throw new Error('Simulated Web3 connection failure'); |
| 67 | + }} |
| 68 | + className="w-full" |
| 69 | + > |
| 70 | + Trigger Web3 Error |
| 71 | + </Button> |
| 72 | + </ErrorBoundaryPresets.web3> |
| 73 | + </CardContent> |
| 74 | + </Card> |
| 75 | + |
| 76 | + {/* Network Error Boundary */} |
| 77 | + <Card> |
| 78 | + <CardHeader> |
| 79 | + <CardTitle>Network Error Boundary</CardTitle> |
| 80 | + </CardHeader> |
| 81 | + <CardContent> |
| 82 | + <p className="text-gray-600 dark:text-gray-300 mb-4"> |
| 83 | + Handles network connectivity issues with retry mechanisms. |
| 84 | + </p> |
| 85 | + <ErrorBoundaryPresets.network enableRetry maxRetries={5}> |
| 86 | + <Button |
| 87 | + onClick={() => { |
| 88 | + throw new Error('Simulated network timeout'); |
| 89 | + }} |
| 90 | + className="w-full" |
| 91 | + > |
| 92 | + Trigger Network Error |
| 93 | + </Button> |
| 94 | + </ErrorBoundaryPresets.network> |
| 95 | + </CardContent> |
| 96 | + </Card> |
| 97 | + |
| 98 | + {/* AR Error Boundary */} |
| 99 | + <Card> |
| 100 | + <CardHeader> |
| 101 | + <CardTitle>AR Error Boundary</CardTitle> |
| 102 | + </CardHeader> |
| 103 | + <CardContent> |
| 104 | + <p className="text-gray-600 dark:text-gray-300 mb-4"> |
| 105 | + Handles AR/VR feature errors with device capability checks. |
| 106 | + </p> |
| 107 | + <ErrorBoundaryPresets.ar enableRetry maxRetries={2}> |
| 108 | + <Button |
| 109 | + onClick={() => { |
| 110 | + throw new Error('Simulated AR camera access denied'); |
| 111 | + }} |
| 112 | + className="w-full" |
| 113 | + > |
| 114 | + Trigger AR Error |
| 115 | + </Button> |
| 116 | + </ErrorBoundaryPresets.ar> |
| 117 | + </CardContent> |
| 118 | + </Card> |
| 119 | + |
| 120 | + {/* UI Error Boundary */} |
| 121 | + <Card> |
| 122 | + <CardHeader> |
| 123 | + <CardTitle>UI Error Boundary</CardTitle> |
| 124 | + </CardHeader> |
| 125 | + <CardContent> |
| 126 | + <p className="text-gray-600 dark:text-gray-300 mb-4"> |
| 127 | + Handles general UI component errors with graceful degradation. |
| 128 | + </p> |
| 129 | + <ErrorBoundaryPresets.ui enableRetry maxRetries={3}> |
| 130 | + <Button |
| 131 | + onClick={() => { |
| 132 | + throw new Error('Simulated UI component failure'); |
| 133 | + }} |
| 134 | + className="w-full" |
| 135 | + > |
| 136 | + Trigger UI Error |
| 137 | + </Button> |
| 138 | + </ErrorBoundaryPresets.ui> |
| 139 | + </CardContent> |
| 140 | + </Card> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + |
| 144 | + {/* Graceful Degradation Example */} |
| 145 | + <div> |
| 146 | + <h3 className="text-2xl font-bold text-gray-900 dark:text-white mb-6"> |
| 147 | + Graceful Degradation Example |
| 148 | + </h3> |
| 149 | + <Card> |
| 150 | + <CardHeader> |
| 151 | + <CardTitle>Fallback Component</CardTitle> |
| 152 | + </CardHeader> |
| 153 | + <CardContent> |
| 154 | + <p className="text-gray-600 dark:text-gray-300 mb-4"> |
| 155 | + Shows how non-critical features can degrade gracefully. |
| 156 | + </p> |
| 157 | + <ErrorBoundaryPresets.ui |
| 158 | + gracefulDegradation={{ |
| 159 | + fallbackComponent: ( |
| 160 | + <div className="p-4 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg"> |
| 161 | + <h4 className="font-medium text-yellow-800 dark:text-yellow-200 mb-2"> |
| 162 | + Feature Unavailable |
| 163 | + </h4> |
| 164 | + <p className="text-sm text-yellow-700 dark:text-yellow-300"> |
| 165 | + This feature is currently unavailable, but you can continue using other parts of the application. |
| 166 | + </p> |
| 167 | + </div> |
| 168 | + ) |
| 169 | + }} |
| 170 | + > |
| 171 | + <Button |
| 172 | + onClick={() => { |
| 173 | + throw new Error('Non-critical feature error'); |
| 174 | + }} |
| 175 | + className="w-full" |
| 176 | + > |
| 177 | + Trigger Graceful Degradation |
| 178 | + </Button> |
| 179 | + </ErrorBoundaryPresets.ui> |
| 180 | + </CardContent> |
| 181 | + </Card> |
| 182 | + </div> |
| 183 | + </div> |
| 184 | + </main> |
| 185 | + </div> |
| 186 | + ); |
| 187 | +} |
| 188 | + |
| 189 | +export default ErrorDemo; |
0 commit comments