With this method, you can catch any error with the stream, and return relevant UI. On the client, you can also use a React Error Boundary to wrap the streamed component and catch any additional errors.
app/page.tsx
'use client';import { getStreamedUI } from '@/actions';import { useState } from 'react';import { ErrorBoundary } from './ErrorBoundary';export default function Page() { const [streamedUI, setStreamedUI] = useState(null); return ( <div> <button onClick={async () => { const newUI = await getStreamedUI(); setStreamedUI(newUI); }} > What does the new UI look like? </button> <ErrorBoundary>{streamedUI}</ErrorBoundary> </div> );}