Add required conversions for returning Error from server functions
All checks were successful
Push Workflows / rustfmt (push) Successful in 5s
Push Workflows / tailwind-build (push) Successful in 5s
Push Workflows / test (push) Successful in 18s
Push Workflows / clippy (push) Successful in 14s
Push Workflows / docs (push) Successful in 18s
Push Workflows / build (push) Successful in 42s
Push Workflows / nix-build (push) Successful in 4m50s
All checks were successful
Push Workflows / rustfmt (push) Successful in 5s
Push Workflows / tailwind-build (push) Successful in 5s
Push Workflows / test (push) Successful in 18s
Push Workflows / clippy (push) Successful in 14s
Push Workflows / docs (push) Successful in 18s
Push Workflows / build (push) Successful in 42s
Push Workflows / nix-build (push) Successful in 4m50s
This commit is contained in:
@@ -220,6 +220,27 @@ impl fmt::Display for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ServerFnError> 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<R> {
|
||||
/// Add context to the `Result` if it is an `Err`.
|
||||
#[track_caller]
|
||||
|
||||
Reference in New Issue
Block a user