Replies: 2 comments 2 replies
-
change the
you can also just add a variant to your enum |
Beta Was this translation helpful? Give feedback.
-
Not sure if you're still interested in this, but leptos v0.8 finally makes this a lot easier (see #3274) It enables your server functions to return your own custom error type directly if it implements Basically (with #[derive(Debug, Clone, Error, Deserialize, Serialize)]
pub enum ApiError {
#[error("server fn error: {0}")]
ServerFn(ServerFnErrorErr),
#[error("some kind {0}")]
Custom(String)
[...]
}
impl FromServerFnError for ApiError {
fn from_server_fn_error(value: ServerFnErrorErr) -> Self {
ApiError::ServerFn(value)
}
}
#[server]
pub async fn foo(bar: u32) -> Result<(), ApiError> {
do_stuff()?;
if bar == 1 {
Err(ApiError::Custom(String::new()))
} else {
Ok(())
}
} And you can match them in the frontend easily without using any roundabout ways all you want :D |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to test the feature referenced by #1830 (comment) but can't get my head how to use it.
From what I get, the From trait implements something like
From<Origin> for Dest
, so the following example doesn't make sense to me, how can it returnServerFnError<MyAppError>
if it's implementing a From forMyAppError
?Compile output
So I guess I need to put some "real" error type on the function. Tried with
MyAppError
:Compile output
So trying at random to return
MyAppError
from the function:Compile output
I'm at a loss, can't wrap how to return a custom error without resorting to String conversion. Maybe starting Rust with a Leptos project was not a good idea.
Beta Was this translation helpful? Give feedback.
All reactions