Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions client/src/components/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';

class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null };
}

static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
return { hasError: true, error };
}

componentDidCatch(error, errorInfo) {
// You can also log the error to an error reporting service
console.error("ErrorBoundary caught an error:", error, errorInfo);
}

handleReload = () => {
window.location.reload();
};

render() {
if (this.state.hasError) {
return (
<div className="flex flex-col items-center justify-center min-h-screen p-6 bg-[var(--bg-page)] text-[var(--text-base)]">
<div className="max-w-md w-full p-8 rounded-xl bg-[var(--bg-card)] border border-[var(--border)] shadow-lg flex flex-col items-center text-center">
<svg
className="w-16 h-16 text-red-500 mb-4"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
/>
</svg>
<h2 className="text-2xl font-bold mb-2">Something went wrong</h2>
<p className="text-[var(--text-muted)] mb-6 break-words w-full">
{this.state.error?.message || "An unexpected application error occurred."}
Comment thread
vivek0028 marked this conversation as resolved.
</p>
<button
onClick={this.handleReload}
className="px-6 py-2 bg-green-500 hover:bg-green-600 text-white font-medium rounded-lg transition-colors"
>
Reload Application
</button>
</div>
</div>
);
}

return this.props.children;
}
}

export default ErrorBoundary;
9 changes: 6 additions & 3 deletions client/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import { ThemeProvider } from "./components/ThemeContext.jsx";
import ErrorBoundary from "./components/ErrorBoundary.jsx";
import "./styles.css";

ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<ThemeProvider>
<App />
</ThemeProvider>
<ErrorBoundary>
<ThemeProvider>
<App />
</ThemeProvider>
</ErrorBoundary>
</React.StrictMode>
);
Loading