fix(hermes): handle non-existent ids on ws
This commit is contained in:
parent
37ff02f1f9
commit
f36bd21f31
|
@ -1764,7 +1764,7 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermes"
|
name = "hermes"
|
||||||
version = "0.1.9"
|
version = "0.1.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "hermes"
|
name = "hermes"
|
||||||
version = "0.1.9"
|
version = "0.1.10"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -227,10 +227,36 @@ impl Subscriber {
|
||||||
verbose,
|
verbose,
|
||||||
binary,
|
binary,
|
||||||
}) => {
|
}) => {
|
||||||
for id in ids {
|
let price_ids: Vec<PriceIdentifier> = ids.into_iter().map(|id| id.into()).collect();
|
||||||
let price_id: PriceIdentifier = id.into();
|
let available_price_ids = self.store.get_price_feed_ids().await;
|
||||||
self.price_feeds_with_config
|
|
||||||
.insert(price_id, PriceFeedClientConfig { verbose, binary });
|
let not_found_price_ids: Vec<&PriceIdentifier> = price_ids
|
||||||
|
.iter()
|
||||||
|
.filter(|price_id| !available_price_ids.contains(price_id))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// If there is a single price id that is not found, we don't subscribe to any of the
|
||||||
|
// asked correct price feed ids and return an error to be more explicit and clear.
|
||||||
|
if !not_found_price_ids.is_empty() {
|
||||||
|
self.sender
|
||||||
|
.send(
|
||||||
|
serde_json::to_string(&ServerMessage::Response(
|
||||||
|
ServerResponseMessage::Err {
|
||||||
|
error: format!(
|
||||||
|
"Price feed(s) with id(s) {:?} not found",
|
||||||
|
not_found_price_ids
|
||||||
|
),
|
||||||
|
},
|
||||||
|
))?
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
} else {
|
||||||
|
for price_id in price_ids {
|
||||||
|
self.price_feeds_with_config
|
||||||
|
.insert(price_id, PriceFeedClientConfig { verbose, binary });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ClientMessage::Unsubscribe { ids }) => {
|
Ok(ClientMessage::Unsubscribe { ids }) => {
|
||||||
|
|
Loading…
Reference in New Issue