Add AuthError
This commit is contained in:
@@ -239,6 +239,7 @@ impl From<ServerFnError> 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<T, E: Into<Error>> Contextualize<Result<T>> 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<fred::error::Error> 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),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user