Skip to content

Commit

Permalink
Merge pull request paritytech#1 from paritytech/na-ignore-close-fix
Browse files Browse the repository at this point in the history
simplify ignoring errors sending to front
  • Loading branch information
gregdhill committed Mar 10, 2021
2 parents 0ee62c3 + 67c58e7 commit 73e9a18
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions ws-client/src/client.rs
Expand Up @@ -373,39 +373,33 @@ fn process_response(

match manager.request_status(&response_id) {
RequestStatus::PendingMethodCall => {
let send_back_oneshot = manager.complete_pending_call(response_id).ok_or(Error::InvalidRequestId)?;
let send_back_oneshot = match manager.complete_pending_call(response_id) {
Some(Some(send)) => send,
Some(None) => return Ok(None),
None => return Err(Error::InvalidRequestId),
};

manager.reclaim_request_id(response_id);
let response = response.try_into().map_err(Error::Request);
match send_back_oneshot.map(|tx| tx.send(response)) {
Some(Err(Err(e))) => Err(e),
// ignore error on channel close
Some(Err(Ok(_))) => Ok(None),
Some(Ok(_)) => Ok(None),
None => Ok(None),
}
let _ = send_back_oneshot.send(response);
Ok(None)
}
RequestStatus::PendingSubscription => {
let (send_back_oneshot, unsubscribe_method) =
manager.complete_pending_subscription(response_id).ok_or(Error::InvalidRequestId)?;
let json_sub_id: JsonValue = match response.try_into() {
Ok(response) => response,
Err(e) => {
return match send_back_oneshot.send(Err(Error::Request(e))) {
Err(Err(e)) => Err(e),
Err(Ok(_)) => unreachable!("Error sent above; qed"),
_ => Ok(None),
};
let _ = send_back_oneshot.send(Err(Error::Request(e)));
return Ok(None);
}
};

let sub_id: SubscriptionId = match jsonrpc::from_value(json_sub_id.clone()) {
Ok(sub_id) => sub_id,
Err(_) => {
return match send_back_oneshot.send(Err(Error::InvalidSubscriptionId)) {
Err(Err(e)) => Err(e),
Err(Ok(_)) => unreachable!("Error sent above; qed"),
_ => Ok(None),
}
let _ = send_back_oneshot.send(Err(Error::InvalidSubscriptionId));
return Ok(None);
}
};

Expand All @@ -422,11 +416,8 @@ fn process_response(
}
}
} else {
match send_back_oneshot.send(Err(Error::InvalidSubscriptionId)) {
Err(Err(e)) => Err(e),
Err(Ok(_)) => unreachable!("Error sent above; qed"),
_ => Ok(None),
}
let _ = send_back_oneshot.send(Err(Error::InvalidSubscriptionId));
Ok(None)
}
}
RequestStatus::Subscription | RequestStatus::Invalid => Err(Error::InvalidRequestId),
Expand Down

0 comments on commit 73e9a18

Please sign in to comment.