dioxus_fullstack_core/
errors.rs1use crate::serialize_context;
4use dioxus_core::{spawn_isomorphic, CapturedError, ErrorContext, ReactiveContext};
5use futures_util::StreamExt;
6
7pub fn init_error_boundary() -> ErrorContext {
9 let initial_error = serialize_context().create_entry::<Option<CapturedError>>();
10 let (rx_context, mut rx) = ReactiveContext::new();
11 let errors = ErrorContext::new(None);
12 if let Ok(Some(err)) = initial_error.get() {
13 errors.insert_error(err);
14 }
15 rx_context.run_in(|| {
16 errors.error();
17 });
18 spawn_isomorphic({
19 let errors = errors.clone();
20 async move {
21 if rx.next().await.is_some() {
22 rx_context.run_in(|| {
23 initial_error.insert(&errors.error(), std::panic::Location::caller())
24 });
25 }
26 }
27 });
28 errors
29}