javascript / expert
Snippet
Granular Error Recovery in Concurrent Streaming Architectures
Utilize the 'digest' property provided by Next.js in error boundaries to map opaque server-side errors to specific client-side recovery strategies. This is critical in streaming environments where errors may occur mid-chunk.
snippet.js
javascript
1
2
3
4
5
6
7
8
9
10
export default function ErrorBoundary({ error, reset }) {const isAuthError = error.digest === 'AUTH_REQUIRED';return (<div>{isAuthError ? <LoginPrompt /> : <p>Generic Error</p>}<button onClick={() => reset()}>Try Again</button></div>);}
nextjs
Breakdown
1
error.digest
A unique hash or ID sent from the server to identify specific error types.
2
reset()
A function to trigger a re-render of the segment to attempt recovery.
3
isAuthError
Conditional logic to provide specific UI based on the error identity.