Prevent infinite spinner when DB connection fails at startup by adding a 10s timeout on connectActiveProfile(). Add ErrorBoundary to catch React crashes and ErrorPage with refresh, update check, and contact links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
34 lines
782 B
TypeScript
34 lines
782 B
TypeScript
import { Component, type ReactNode } from "react";
|
|
import ErrorPage from "./ErrorPage";
|
|
|
|
interface Props {
|
|
children: ReactNode;
|
|
}
|
|
|
|
interface State {
|
|
hasError: boolean;
|
|
error: string | null;
|
|
}
|
|
|
|
export default class ErrorBoundary extends Component<Props, State> {
|
|
constructor(props: Props) {
|
|
super(props);
|
|
this.state = { hasError: false, error: null };
|
|
}
|
|
|
|
static getDerivedStateFromError(error: Error): State {
|
|
return { hasError: true, error: error.message };
|
|
}
|
|
|
|
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
console.error("ErrorBoundary caught an error:", error, errorInfo);
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
return <ErrorPage error={this.state.error ?? undefined} />;
|
|
}
|
|
|
|
return this.props.children;
|
|
}
|
|
}
|