From 3640039168b3abc5a35953857001fc43e73c1d4f Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sun, 21 Jun 2026 13:55:40 -0400 Subject: [PATCH] Add required conversions for returning Error from server functions --- src/util/error.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/util/error.rs b/src/util/error.rs index fc0aa54..805cfa4 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -220,6 +220,27 @@ impl fmt::Display for Error { } } +impl From for Error { + #[track_caller] + fn from(err: ServerFnError) -> Error { + Error::new_here(ErrorType::ServerFnError(err)) + } +} + +#[cfg(feature = "server")] +impl dioxus_fullstack::AsStatusCode for Error { + fn as_status_code(&self) -> StatusCode { + match &self.source { + ErrorType::Database(msg) if *msg == (diesel::result::Error::NotFound).to_string() => { + StatusCode::NOT_FOUND + } + ErrorType::Database(_) => StatusCode::INTERNAL_SERVER_ERROR, + ErrorType::Error(_) => StatusCode::INTERNAL_SERVER_ERROR, + ErrorType::ServerFnError(e) => e.as_status_code(), + } + } +} + pub trait Contextualize { /// Add context to the `Result` if it is an `Err`. #[track_caller]