mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
Introduce custom errors
This commit is contained in:
parent
5abff453b9
commit
6b8cccede0
11
src/domain/error.rs
Normal file
11
src/domain/error.rs
Normal 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>;
|
@ -1,7 +1,6 @@
|
|||||||
use super::sql_tables::*;
|
use super::sql_tables::*;
|
||||||
use crate::domain::sql_tables::Pool;
|
use crate::domain::{error::*, sql_tables::Pool};
|
||||||
use crate::infra::configuration::Configuration;
|
use crate::infra::configuration::Configuration;
|
||||||
use anyhow::{bail, Result};
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use futures_util::TryStreamExt;
|
use futures_util::TryStreamExt;
|
||||||
@ -61,7 +60,8 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
if request.password == self.config.ldap_user_pass {
|
if request.password == self.config.ldap_user_pass {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} 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()
|
let query = Query::select()
|
||||||
@ -78,7 +78,7 @@ impl BackendHandler for SqlBackendHandler {
|
|||||||
} else {
|
} else {
|
||||||
debug!(r#"No user found for "{}""#, request.name);
|
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>> {
|
async fn list_users(&self, request: ListUsersRequest) -> Result<Vec<User>> {
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
|
pub mod error;
|
||||||
pub mod handler;
|
pub mod handler;
|
||||||
pub mod sql_tables;
|
pub mod sql_tables;
|
||||||
|
Loading…
Reference in New Issue
Block a user