diff --git a/ui/src/app/jobs/new/page.tsx b/ui/src/app/jobs/new/page.tsx index d1b7f9ca..a5e69c24 100644 --- a/ui/src/app/jobs/new/page.tsx +++ b/ui/src/app/jobs/new/page.tsx @@ -19,6 +19,7 @@ import { Button } from '@headlessui/react'; import { FaChevronLeft } from 'react-icons/fa'; import SimpleJob from './SimpleJob'; import AdvancedJob from './AdvancedJob'; +import ErrorBoundary from '@/components/ErrorBoundary'; import { apiClient } from '@/utils/api'; const isDev = process.env.NODE_ENV === 'development'; @@ -179,21 +180,27 @@ export default function TrainingForm() { ) : ( - + + Advanced job detected. Please switch to advanced view to continue. + + }> + +
)} ); -} +} \ No newline at end of file diff --git a/ui/src/components/ErrorBoundary.tsx b/ui/src/components/ErrorBoundary.tsx new file mode 100644 index 00000000..7d1a6eca --- /dev/null +++ b/ui/src/components/ErrorBoundary.tsx @@ -0,0 +1,41 @@ +// ErrorBoundary.tsx +'use client'; + +import React, { ReactNode, ErrorInfo, Component } from 'react'; + +interface ErrorBoundaryProps { + children: ReactNode; + fallback?: ReactNode; +} + +interface ErrorBoundaryState { + hasError: boolean; +} + +class ErrorBoundary extends Component { + constructor(props: ErrorBoundaryProps) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(_: Error): ErrorBoundaryState { + // Update state so the next render will show the fallback UI + return { hasError: true }; + } + + componentDidCatch(error: Error, errorInfo: ErrorInfo): void { + // You can log the error to an error reporting service + console.error("Error caught by ErrorBoundary:", error, errorInfo); + } + + render(): ReactNode { + if (this.state.hasError) { + // You can render any custom fallback UI + return this.props.fallback ||
Something went wrong.
; + } + + return this.props.children; + } +} + +export default ErrorBoundary; \ No newline at end of file