From fc2c08c7c9ca7d42f70629275ab108a9696f0daa Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 25 Feb 2021 12:52:38 +1100 Subject: [PATCH] Error only on close message when fetching the rate Messages Ping, Pong and Binary are ignored and not reported as error. --- swap/src/asb/kraken.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swap/src/asb/kraken.rs b/swap/src/asb/kraken.rs index 4f8e36b0..4cdad0ec 100644 --- a/swap/src/asb/kraken.rs +++ b/swap/src/asb/kraken.rs @@ -36,8 +36,8 @@ impl LatestRate for RateService { pub enum Error { #[error("Rate has not yet been retrieved from Kraken websocket API")] NotYetRetrieved, - #[error("Message is not text")] - NonTextMessage, + #[error("Received close message from Kraken")] + CloseMessage, #[error("Websocket: ")] WebSocket(String), #[error("Serde: ")] @@ -77,8 +77,11 @@ impl RateService { while let Some(msg) = rate_stream.next().await { let msg = match msg { Ok(Message::Text(msg)) => msg, + Ok(Message::Close(..)) => { + let _ = rate_update.send(Err(Error::CloseMessage)); + continue; + } Ok(_) => { - let _ = rate_update.send(Err(Error::NonTextMessage)); continue; } Err(e) => {