Replies: 2 comments
-
As far as Error handling goes, this is working as designed. A server function returns an error, and then the user has a choice of how to handle it on the frontend. If you look in the actual Response in the browser inspector, you will most likely see the Display trait message in the response. That's how I usually debug things with 500s on the server I'm open to suggestions, perhaps it would be a good idea to automatically print the display error in the console in debug mode. |
Beta Was this translation helpful? Give feedback.
-
Maybe another approach is to use #[tracing::instrument(err)]
#[server]
async fn do_something(
should_error: Option<String>,
) -> Result<String, ServerFnError> {
if should_error.is_none() {
Ok(String::from("Successful submit"))
} else {
Err(ServerFnError::ServerError(String::from(
"You got an error!",
)))
}
} I'm returning exceptions like |
Beta Was this translation helpful? Give feedback.
-
Hello,
I created a new project using
cargo leptos new --git leptos-rs/start-axum
and modified theapp.rs
with some code from theleptos/examples/action-form-error-handling
:When I run
cargo leptos watch
and navigate to the home page, I see:printed in the server console. Then if I toggle the "Should error" checkbox and submit the form, the page shows the error display, and the console shows a 500 Server Error with the message "You got an error!". But there is nothing in the server console.
My question is how to make the server console show the error automatically as well.
One option is to add a
logging::log!("You got an error!");
before returning the server error:but I would like it to be automatic.
I considered creating my own Error type and returning that instead, with a log in the
Display
implementation of the error:Is this the best approach, or is there a simpler way to have errors displayed in the server console automatically?
Beta Was this translation helpful? Give feedback.
All reactions