From 7d92e52a6e51beb81042536eb811bc525fdfbece Mon Sep 17 00:00:00 2001 From: jokemanfire Date: Sat, 12 Oct 2024 10:28:00 +0800 Subject: [PATCH] async:when the client request failed. Learn from ttrpc-go The error type shuld more friendly to external interfaces --- src/asynchronous/client.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/asynchronous/client.rs b/src/asynchronous/client.rs index 706a9474..ca8f2f71 100644 --- a/src/asynchronous/client.rs +++ b/src/asynchronous/client.rs @@ -84,12 +84,12 @@ impl Client { self.req_tx .send(SendingMessage::new(msg)) .await - .map_err(|e| Error::Others(format!("Send packet to sender error {e:?}")))?; + .map_err(|e| Error::LocalClosed)?; let result = if timeout_nano == 0 { rx.recv() .await - .ok_or_else(|| Error::Others("Receive packet from receiver error".to_string()))? + .ok_or_else(|| Error::RemoteClosed)? } else { tokio::time::timeout( std::time::Duration::from_nanos(timeout_nano as u64), @@ -97,7 +97,7 @@ impl Client { ) .await .map_err(|e| Error::Others(format!("Receive packet timeout {e:?}")))? - .ok_or_else(|| Error::Others("Receive packet from receiver error".to_string()))? + .ok_or_else(|| Error::RemoteClosed)? }; let msg = result?;