fix(notification): fix wrongly error report in notification (#70)

This commit is contained in:
4t145 2025-03-31 13:50:27 +08:00 • committed by GitHub
commit 145b5de322
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 121 additions and 10 deletions

View file

@ -103,7 +103,7 @@ impl<H: ServerHandler> Service<RoleServer> for H {
}
#[allow(unused_variables)]
pub trait ServerHandler: Sized + Clone + Send + Sync + 'static {
pub trait ServerHandler: Sized + Send + Sync + 'static {
fn ping(
&self,
context: RequestContext<RoleServer>,

View file

@ -342,10 +342,12 @@ impl<R: ServiceRole> Peer<R> {
self.tx
.send(PeerSinkMessage::Notification(notification, responder))
.await
.map_err(|_m| ServiceError::Transport(std::io::Error::other("disconnected")))?;
receiver
.await
.map_err(|_e| ServiceError::Transport(std::io::Error::other("disconnected")))?
.map_err(|_m| {
ServiceError::Transport(std::io::Error::other("disconnected: receiver dropped"))
})?;
receiver.await.map_err(|_e| {
ServiceError::Transport(std::io::Error::other("disconnected: responder dropped"))
})?
}
pub async fn send_request(&self, request: R::Req) -> Result<R::PeerResp, ServiceError> {
self.send_cancellable_request(request, PeerRequestOptions::no_options())
@ -578,10 +580,12 @@ where
let send_result = sink
.send(Message::Notification(notification).into_json_rpc_message())
.await;
if let Err(e) = send_result {
let _ =
responder.send(Err(ServiceError::Transport(std::io::Error::other(e))));
}
let response = if let Err(e) = send_result {
Err(ServiceError::Transport(std::io::Error::other(e)))
} else {
Ok(())
};
let _ = responder.send(response);
if let Some(param) = cancellation_param {
if let Some(responder) = local_responder_pool.remove(&param.request_id) {
tracing::info!(id = %param.request_id, reason = param.reason, "cancelled");