Files
ServerKit/frontend/src/components/ErrorBoundary.jsx
T
Juan DenisandClaude Opus 4.8 ad9acb89e3 refactor(frontend): Phase 5 §8.5 — drop 142 unused React imports (JSX transform)
Per docs/plans/FRONTEND_UX_TAILWIND_CLEANUP_PLAN.md §8.5. React 18's automatic
JSX runtime makes 'import React' unnecessary; removed it from the 142 files
eslint flagged as 'React defined but never used' (named imports like useState
preserved). Driven by an eslint --format json pass so only flagged files were
touched.

Lint warnings: 1603 -> 1461 (0 errors). Verified: npm run build passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 02:44:16 -04:00

90 lines
2.7 KiB
React

import { Component } from 'react';
import { AlertTriangle, RefreshCw } from 'lucide-react';
// Class-based Error Boundary for catching React errors
export class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null, errorInfo: null };
}
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, errorInfo) {
this.setState({ errorInfo });
console.error('ErrorBoundary caught an error:', error, errorInfo);
}
handleRetry = () => {
this.setState({ hasError: false, error: null, errorInfo: null });
this.props.onRetry?.();
};
render() {
if (this.state.hasError) {
return (
<div className="error-boundary">
<div className="error-boundary-icon">
<AlertTriangle size={32} />
</div>
<h3>Something went wrong</h3>
<p className="error-boundary-message">
{this.state.error?.message || 'An unexpected error occurred'}
</p>
<button className="btn btn-primary" onClick={this.handleRetry}>
<RefreshCw size={14} />
Try Again
</button>
</div>
);
}
return this.props.children;
}
}
// Functional component for displaying API/fetch errors
export function ErrorState({
title = 'Failed to load',
message,
error,
onRetry,
compact = false
}) {
const errorMessage = message || error?.message || 'An error occurred while loading data';
if (compact) {
return (
<div className="error-state-compact">
<AlertTriangle size={16} />
<span>{errorMessage}</span>
{onRetry && (
<button className="btn btn-ghost btn-sm" onClick={onRetry}>
<RefreshCw size={14} /> Retry
</button>
)}
</div>
);
}
return (
<div className="error-state">
<div className="error-state-icon">
<AlertTriangle size={32} />
</div>
<h3 className="error-state-title">{title}</h3>
<p className="error-state-message">{errorMessage}</p>
{onRetry && (
<button className="btn btn-primary" onClick={onRetry}>
<RefreshCw size={14} />
Try Again
</button>
)}
</div>
);
}
export default ErrorBoundary;