fix: Slightly better error passing to the client
This commit is contained in:
parent
39c70d297e
commit
a30e9c3dd9
3 changed files with 11 additions and 11 deletions
|
|
@ -33,14 +33,12 @@ impl BasicLdapClient {
|
|||
t
|
||||
}
|
||||
Ok(Err(err)) => {
|
||||
// trace!(?addr, ?err, "error");
|
||||
error!("error to {addr}: {err}");
|
||||
panic!();
|
||||
return Err(LdapError::ConnectError);
|
||||
}
|
||||
Err(_) => {
|
||||
warn!("timeout to {addr}");
|
||||
panic!();
|
||||
// continue;
|
||||
return Err(LdapError::Transport);
|
||||
}
|
||||
};
|
||||
unixstream.into()
|
||||
|
|
@ -53,12 +51,11 @@ impl BasicLdapClient {
|
|||
Ok(Err(err)) => {
|
||||
// trace!(?addr, ?err, "error");
|
||||
error!("error to {addr}: {err}");
|
||||
panic!();
|
||||
return Err(LdapError::ConnectError);
|
||||
}
|
||||
Err(_) => {
|
||||
warn!("timeout to {addr}");
|
||||
panic!();
|
||||
// continue;
|
||||
return Err(LdapError::Transport);
|
||||
}
|
||||
};
|
||||
tcpstream.into()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ use std::sync::Arc;
|
|||
|
||||
use crate::{BasicLdapClient, ClientState, Config, Dn, LdapError};
|
||||
|
||||
pub fn bind_operror(msgid: i32, msg: &str) -> LdapMsg {
|
||||
// TODO: replace with a more generic approach for different op response types
|
||||
// (bind, search) and custom error codes
|
||||
pub fn bind_operror(msgid: i32, msg: &dyn ToString) -> LdapMsg {
|
||||
LdapMsg {
|
||||
msgid,
|
||||
op: LdapOp::BindResponse(LdapBindResponse {
|
||||
|
|
@ -97,7 +99,8 @@ pub async fn bind<W: AsyncWrite + Unpin>(
|
|||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
error!("A client build error has occurred: {e:?}");
|
||||
let resp_msg = bind_operror(msgid, "unable to bind");
|
||||
// TODO: send more detailed error to the client (connection refused / timeout)
|
||||
let resp_msg = bind_operror(msgid, &"unable to bind");
|
||||
w.send(resp_msg).await.map_err(|err| {
|
||||
error!("Unable to send response: {err}");
|
||||
LdapError::Transport
|
||||
|
|
@ -125,7 +128,7 @@ pub async fn bind<W: AsyncWrite + Unpin>(
|
|||
}
|
||||
Err(e) => {
|
||||
error!("A client bind error has occurred: {e:?}");
|
||||
let resp_msg = bind_operror(msgid, "unable to bind");
|
||||
let resp_msg = bind_operror(msgid, &"unable to bind");
|
||||
w.send(resp_msg).await.map_err(|err| {
|
||||
error!("Unable to send response: {err}");
|
||||
LdapError::Transport
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub async fn search<W: AsyncWrite + Unpin>(
|
|||
Ok(data) => data,
|
||||
Err(e) => {
|
||||
error!("A client search error has occurred: {e:?}");
|
||||
let resp_msg = bind_operror(msgid, "unable to search");
|
||||
let resp_msg = bind_operror(msgid, &"unable to search");
|
||||
w.send(resp_msg).await.map_err(|err| {
|
||||
error!("Unable to send response: {err}");
|
||||
LdapError::Transport
|
||||
|
|
|
|||
Loading…
Reference in a new issue