Files
ProjectE/apps/web-legacy/components/widget-error-boundary.tsx
T
Hermes fca56ab77e T1/Phase 1: scaffold Vite SPA + Hono API + Bun worker
- apps/web: Vite + React 19 + TanStack Router/Query + shadcn/ui
   - apps/api: Hono + Bun on :3001 with /api/health, /api/auth/*, /mcp stubs
   - apps/worker: Bun worker stub, DB connection, graceful SIGTERM
   - apps/web-legacy/: old Next.js code moved aside (preserved for T2-T8 reference)
   - Dockerfiles: api (Bun), worker (Bun), spa (multi-stage Caddy)
   - Caddyfile: serves dist + reverse-proxies /api/* + /mcp to api
   - docker-compose.yml: 4-service target (api, spa, db, worker)
   - packages/db/src/client.ts: shared Drizzle client for api + worker
   - db/client.ts: root-level alias for convenience

   Parent: t_e1cbd87d -> t_24c9c3fd (T0)
2026-08-01 01:15:31 +00:00

63 lines
1.5 KiB
TypeScript

'use client';
import { Component, type ReactNode } from 'react';
import { Button } from '@/components/ui/button';
interface Props {
children: ReactNode;
fallback?: ReactNode;
widgetName?: string;
}
interface State {
hasError: boolean;
error: Error | null;
}
export class WidgetErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error: Error): State {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error(
`Widget error (${this.props.widgetName || 'unknown'}):`,
error,
errorInfo
);
}
render() {
if (this.state.hasError) {
if (this.props.fallback) {
return this.props.fallback;
}
return (
<div className="flex h-full min-h-[200px] flex-col items-center justify-center gap-3 rounded-lg border border-destructive/20 bg-destructive/5 p-4">
<p className="text-sm font-medium text-destructive">
{this.props.widgetName || 'Widget'} failed to load
</p>
<p className="text-xs text-muted-foreground text-center">
{this.state.error?.message || 'An unexpected error occurred'}
</p>
<Button
variant="outline"
size="sm"
onClick={() => this.setState({ hasError: false, error: null })}
>
Retry
</Button>
</div>
);
}
return this.props.children;
}
}