Introduce custom errors

This commit is contained in:
Valentin Tolmer 2021-05-10 09:34:38 +02:00
parent 5abff453b9
commit 6b8cccede0
3 changed files with 16 additions and 4 deletions

11
src/domain/error.rs Normal file
View File

@ -0,0 +1,11 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Authentication error for `{0}`")]
AuthenticationError(String),
#[error("Database error")]
DatabaseError(#[from] sqlx::Error),
}
pub type Result<T> = std::result::Result<T, Error>;

View File

@ -1,7 +1,6 @@
use super::sql_tables::*;
use crate::domain::sql_tables::Pool;
use crate::domain::{error::*, sql_tables::Pool};
use crate::infra::configuration::Configuration;
use anyhow::{bail, Result};
use async_trait::async_trait;
use futures_util::StreamExt;
use futures_util::TryStreamExt;
@ -61,7 +60,8 @@ impl BackendHandler for SqlBackendHandler {
if request.password == self.config.ldap_user_pass {
return Ok(());
} else {
bail!(r#"Authentication error for "{}""#, request.name)
debug!(r#"Invalid password for LDAP bind user"#);
return Err(Error::AuthenticationError(request.name));
}
}
let query = Query::select()
@ -78,7 +78,7 @@ impl BackendHandler for SqlBackendHandler {
} else {
debug!(r#"No user found for "{}""#, request.name);
}
bail!(r#"Authentication error for "{}""#, request.name)
Err(Error::AuthenticationError(request.name))
}
async fn list_users(&self, request: ListUsersRequest) -> Result<Vec<User>> {

View File

@ -1,2 +1,3 @@
pub mod error;
pub mod handler;
pub mod sql_tables;