Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/components/ErrorBoundary.jsx
Browse files
frontend/src/components/ErrorBoundary.jsx
CHANGED
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
| 3 |
export class ErrorBoundary extends React.Component {
|
| 4 |
constructor(props) {
|
| 5 |
super(props);
|
| 6 |
-
this.state = { hasError: false, error: null };
|
| 7 |
}
|
| 8 |
|
| 9 |
static getDerivedStateFromError(error) {
|
|
@@ -12,8 +12,16 @@ export class ErrorBoundary extends React.Component {
|
|
| 12 |
|
| 13 |
componentDidCatch(error, errorInfo) {
|
| 14 |
console.error("Uncaught Error caught by ErrorBoundary:", error, errorInfo);
|
| 15 |
-
// If it's a chunk loading error (common
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
const hasReloaded = sessionStorage.getItem('chunk_reload_retry');
|
| 18 |
if (!hasReloaded) {
|
| 19 |
sessionStorage.setItem('chunk_reload_retry', 'true');
|
|
@@ -33,44 +41,67 @@ export class ErrorBoundary extends React.Component {
|
|
| 33 |
|
| 34 |
handlePopState = () => {
|
| 35 |
if (this.state.hasError) {
|
| 36 |
-
this.setState({ hasError: false, error: null });
|
| 37 |
}
|
| 38 |
};
|
| 39 |
|
| 40 |
render() {
|
| 41 |
if (this.state.hasError) {
|
| 42 |
return (
|
| 43 |
-
<div className="min-h-screen flex flex-col items-center justify-center bg-
|
| 44 |
-
<div className="bg-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
</div>
|
| 48 |
|
| 49 |
-
<h2 className="text-
|
| 50 |
Something Went Wrong
|
| 51 |
</h2>
|
| 52 |
|
| 53 |
-
<p className="text-sm text-slate-
|
| 54 |
-
Sorry, due to a temporary technical issue, this page could not be displayed properly. Please refresh the page or contact our support team
|
| 55 |
</p>
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
<div className="flex flex-col gap-3">
|
| 58 |
<button
|
| 59 |
onClick={() => {
|
| 60 |
-
this.setState({ hasError: false, error: null });
|
| 61 |
window.location.reload();
|
| 62 |
}}
|
| 63 |
-
className="w-full bg-
|
| 64 |
>
|
| 65 |
-
<span className="material-symbols-outlined text-[
|
| 66 |
Refresh Page
|
| 67 |
</button>
|
| 68 |
|
| 69 |
<a
|
| 70 |
href="mailto:support@larshield.io?subject=LarShield%20System%20Issue%20Report"
|
| 71 |
-
className="w-full bg-slate-
|
| 72 |
>
|
| 73 |
-
<span className="material-symbols-outlined text-[
|
| 74 |
Contact Support Team
|
| 75 |
</a>
|
| 76 |
|
|
@@ -79,9 +110,11 @@ export class ErrorBoundary extends React.Component {
|
|
| 79 |
sessionStorage.clear();
|
| 80 |
localStorage.removeItem('wss_token');
|
| 81 |
localStorage.removeItem('wss_refresh_token');
|
|
|
|
|
|
|
| 82 |
window.location.href = '/login';
|
| 83 |
}}
|
| 84 |
-
className="w-full text-slate-
|
| 85 |
>
|
| 86 |
Clear Session & Return to Login
|
| 87 |
</button>
|
|
|
|
| 3 |
export class ErrorBoundary extends React.Component {
|
| 4 |
constructor(props) {
|
| 5 |
super(props);
|
| 6 |
+
this.state = { hasError: false, error: null, showDetails: false };
|
| 7 |
}
|
| 8 |
|
| 9 |
static getDerivedStateFromError(error) {
|
|
|
|
| 12 |
|
| 13 |
componentDidCatch(error, errorInfo) {
|
| 14 |
console.error("Uncaught Error caught by ErrorBoundary:", error, errorInfo);
|
| 15 |
+
// If it's a chunk loading error (common after new deployments or SPA lazy route updates), auto-reload page once
|
| 16 |
+
const isChunkError = error && (
|
| 17 |
+
error.name === 'ChunkLoadError' ||
|
| 18 |
+
error.message?.includes('dynamically imported module') ||
|
| 19 |
+
error.message?.includes('Importing a module script failed') ||
|
| 20 |
+
error.message?.includes('Failed to fetch dynamically imported module') ||
|
| 21 |
+
error.message?.includes('Failed to load module script')
|
| 22 |
+
);
|
| 23 |
+
|
| 24 |
+
if (isChunkError) {
|
| 25 |
const hasReloaded = sessionStorage.getItem('chunk_reload_retry');
|
| 26 |
if (!hasReloaded) {
|
| 27 |
sessionStorage.setItem('chunk_reload_retry', 'true');
|
|
|
|
| 41 |
|
| 42 |
handlePopState = () => {
|
| 43 |
if (this.state.hasError) {
|
| 44 |
+
this.setState({ hasError: false, error: null, showDetails: false });
|
| 45 |
}
|
| 46 |
};
|
| 47 |
|
| 48 |
render() {
|
| 49 |
if (this.state.hasError) {
|
| 50 |
return (
|
| 51 |
+
<div className="min-h-screen flex flex-col items-center justify-center bg-[#f8fafc] p-6 text-center font-sans">
|
| 52 |
+
<div className="bg-white border border-slate-200/80 shadow-2xl rounded-3xl p-8 max-w-lg w-full animate-fade-in text-slate-900">
|
| 53 |
+
{/* Warning Icon Badge */}
|
| 54 |
+
<div className="w-16 h-16 rounded-2xl bg-amber-500/10 text-amber-600 border border-amber-500/20 flex items-center justify-center mx-auto mb-5 shadow-xs">
|
| 55 |
+
<span className="material-symbols-outlined text-4xl">warning</span>
|
| 56 |
</div>
|
| 57 |
|
| 58 |
+
<h2 className="text-2xl font-black text-slate-900 mb-2 tracking-tight">
|
| 59 |
Something Went Wrong
|
| 60 |
</h2>
|
| 61 |
|
| 62 |
+
<p className="text-sm text-slate-600 mb-6 leading-relaxed font-medium">
|
| 63 |
+
Sorry, due to a temporary technical issue or standard network update, this page could not be displayed properly. Please refresh the page or contact our support team.
|
| 64 |
</p>
|
| 65 |
|
| 66 |
+
{/* Optional Collapsible Technical Details */}
|
| 67 |
+
{this.state.error?.message && (
|
| 68 |
+
<div className="mb-6 text-left">
|
| 69 |
+
<button
|
| 70 |
+
onClick={() => this.setState(prev => ({ showDetails: !prev.showDetails }))}
|
| 71 |
+
className="text-[12px] font-bold text-slate-500 hover:text-primary transition-colors flex items-center gap-1 bg-transparent border-0 cursor-pointer p-0 mb-2 mx-auto"
|
| 72 |
+
>
|
| 73 |
+
<span className="material-symbols-outlined text-[16px]">
|
| 74 |
+
{this.state.showDetails ? 'expand_less' : 'expand_more'}
|
| 75 |
+
</span>
|
| 76 |
+
{this.state.showDetails ? 'Hide Error Details' : 'View Error Details'}
|
| 77 |
+
</button>
|
| 78 |
+
|
| 79 |
+
{this.state.showDetails && (
|
| 80 |
+
<div className="bg-slate-900 text-slate-200 p-3.5 rounded-xl font-mono text-[11px] overflow-x-auto max-h-36 border border-slate-800 break-all select-all leading-relaxed shadow-inner">
|
| 81 |
+
<span className="text-red-400 font-bold">Error:</span> {this.state.error.toString()}
|
| 82 |
+
</div>
|
| 83 |
+
)}
|
| 84 |
+
</div>
|
| 85 |
+
)}
|
| 86 |
+
|
| 87 |
+
{/* Action Buttons */}
|
| 88 |
<div className="flex flex-col gap-3">
|
| 89 |
<button
|
| 90 |
onClick={() => {
|
| 91 |
+
this.setState({ hasError: false, error: null, showDetails: false });
|
| 92 |
window.location.reload();
|
| 93 |
}}
|
| 94 |
+
className="w-full bg-primary hover:brightness-110 text-white font-bold py-3.5 px-6 rounded-xl transition-all shadow-md shadow-primary/20 border-0 cursor-pointer text-sm flex items-center justify-center gap-2 active:scale-[0.99]"
|
| 95 |
>
|
| 96 |
+
<span className="material-symbols-outlined text-[20px]">refresh</span>
|
| 97 |
Refresh Page
|
| 98 |
</button>
|
| 99 |
|
| 100 |
<a
|
| 101 |
href="mailto:support@larshield.io?subject=LarShield%20System%20Issue%20Report"
|
| 102 |
+
className="w-full bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold py-3 px-6 rounded-xl transition-all border border-slate-200/80 cursor-pointer text-sm no-underline flex items-center justify-center gap-2 active:scale-[0.99]"
|
| 103 |
>
|
| 104 |
+
<span className="material-symbols-outlined text-[20px]">support_agent</span>
|
| 105 |
Contact Support Team
|
| 106 |
</a>
|
| 107 |
|
|
|
|
| 110 |
sessionStorage.clear();
|
| 111 |
localStorage.removeItem('wss_token');
|
| 112 |
localStorage.removeItem('wss_refresh_token');
|
| 113 |
+
localStorage.removeItem('superAdminActiveTab');
|
| 114 |
+
localStorage.removeItem('supportEngineerActiveTab');
|
| 115 |
window.location.href = '/login';
|
| 116 |
}}
|
| 117 |
+
className="w-full text-slate-500 hover:text-red-600 text-xs font-bold py-1.5 transition-colors border-0 bg-transparent cursor-pointer mt-1"
|
| 118 |
>
|
| 119 |
Clear Session & Return to Login
|
| 120 |
</button>
|