diff --git a/src/util/error.rs b/src/util/error.rs index b6c4130..c85d51e 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -239,6 +239,7 @@ impl From for Error { impl dioxus_fullstack::AsStatusCode for Error { fn as_status_code(&self) -> StatusCode { match &self.source { + ErrorType::Auth(AuthError::InvalidCredentials) => StatusCode::UNAUTHORIZED, ErrorType::Database(msg) if *msg == (diesel::result::Error::NotFound).to_string() => { StatusCode::NOT_FOUND } @@ -282,6 +283,9 @@ impl> Contextualize> for E { #[derive(Debug, Clone, thiserror::Error, Deserialize, Serialize)] pub enum ErrorType { + #[error("Authentication error: {0}")] + Auth(AuthError), + // Using string to represent Diesel errors, because Diesel's Error type is not `Serialize`, // and Diesel is only available on the server #[error("Database error: {0}")] @@ -331,3 +335,12 @@ impl From for Error { Error::new_here(ErrorType::KeyValStore(format!("{err}"))) } } + +#[derive(Debug, Clone, thiserror::Error, Deserialize, Serialize)] +pub enum AuthError { + #[error("Invalid credentials")] + InvalidCredentials, + + #[error("{0}")] + Error(String), +}