Skip to content

Error boundary with different error types #1528

Answered by fprasx
fprasx asked this question in Q&A
Discussion options

You must be logged in to vote

Hmm, I thought this might be the case, but this doesn't compile due to a similar error:

#[derive(Debug, Error)]
enum MyError {
    #[error("I'm an error")]
    Error,
}

// Compiles
fn impls_into_error() -> leptos::error::Error {
    MyError::Error.into()
}


#[component]
fn NumericInput(cx: Scope) -> impl IntoView {
    let (value, set_value) = create_signal(cx, Ok(0));
    
    // Added a map_err on this line
    let on_input = move |ev| set_value.set(event_target_value(&ev).parse::<i32>().map_err(|_| MyError::Error));
    view! { cx,
        <h1>"Error Handling"</h1>
        <label>
            "Type a number (or something that's not a number!)"
            <input on:input=on_input/>
 …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@gbj
Comment options

@fprasx
Comment options

Answer selected by fprasx
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