import * as Sentry from '@sentry/nextjs' import { AlertCircle } from 'lucide-react' import { ErrorInfo } from 'react' import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary' import { Alert, AlertDescription, AlertTitle, Button } from 'ui' interface ErrorFallbackProps { error: Error resetErrorBoundary: () => void message?: string actions?: { label: string onClick: () => void }[] sentryContext?: Record } const ErrorFallback = ({ error: _error, resetErrorBoundary, message = 'Something went wrong', actions = [], }: ErrorFallbackProps) => { return (
{message} We've been notified and will review and fix this issue.
{actions?.map((action, index) => ( ))}
) } interface ErrorBoundaryProps { children: React.ReactNode message?: string actions?: { label: string onClick: () => void }[] sentryContext?: Record onReset?: () => void } export const ErrorBoundary = ({ children, message, actions, sentryContext, onReset, }: ErrorBoundaryProps) => { const handleError = (error: Error, info: ErrorInfo) => { Sentry.withScope((scope) => { scope.setExtra('componentStack', info.componentStack) if (sentryContext) { Object.entries(sentryContext).forEach(([key, value]) => { scope.setExtra(key, value) }) } Sentry.captureException(error) }) } const handleReset = () => { onReset?.() } return ( ( )} onError={handleError} onReset={handleReset} > {children} ) }