Skip to content

How do I make sure an error from a resource gets caught by a higher level error boundary? #1862

Answered by gbj
SleeplessOne1917 asked this question in Q&A
Discussion options

You must be logged in to vote

Very simply: an ErrorBoundary is triggered if you render an Err(_) inside it.

So:

  1. To trigger the parent boundary: inside that desired boundary, do something like my_resource.and_then(|_| ()) to render either Ok(()) (shows nothing) or Err(_) (triggers error boundary)
  2. To avoid triggering the child boundaries: .unwrap_or_else() the Result to some default value such that it can never render Err under those children

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SleeplessOne1917
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants