diff --git a/src/client.rs b/src/client.rs index 870d622..f7488b3 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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() diff --git a/src/op/bind.rs b/src/op/bind.rs index 7e28aa8..51b5171 100644 --- a/src/op/bind.rs +++ b/src/op/bind.rs @@ -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( 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( } 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 diff --git a/src/op/search.rs b/src/op/search.rs index f5934fc..e7568a6 100644 --- a/src/op/search.rs +++ b/src/op/search.rs @@ -30,7 +30,7 @@ pub async fn search( 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