Skip to content

Commit f36bd21

Browse files
committed
fix(hermes): handle non-existent ids on ws
1 parent 37ff02f commit f36bd21

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

hermes/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hermes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes"
3-
version = "0.1.9"
3+
version = "0.1.10"
44
edition = "2021"
55

66
[dependencies]

hermes/src/api/ws.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,36 @@ impl Subscriber {
227227
verbose,
228228
binary,
229229
}) => {
230-
for id in ids {
231-
let price_id: PriceIdentifier = id.into();
232-
self.price_feeds_with_config
233-
.insert(price_id, PriceFeedClientConfig { verbose, binary });
230+
let price_ids: Vec<PriceIdentifier> = ids.into_iter().map(|id| id.into()).collect();
231+
let available_price_ids = self.store.get_price_feed_ids().await;
232+
233+
let not_found_price_ids: Vec<&PriceIdentifier> = price_ids
234+
.iter()
235+
.filter(|price_id| !available_price_ids.contains(price_id))
236+
.collect();
237+
238+
// If there is a single price id that is not found, we don't subscribe to any of the
239+
// asked correct price feed ids and return an error to be more explicit and clear.
240+
if !not_found_price_ids.is_empty() {
241+
self.sender
242+
.send(
243+
serde_json::to_string(&ServerMessage::Response(
244+
ServerResponseMessage::Err {
245+
error: format!(
246+
"Price feed(s) with id(s) {:?} not found",
247+
not_found_price_ids
248+
),
249+
},
250+
))?
251+
.into(),
252+
)
253+
.await?;
254+
return Ok(());
255+
} else {
256+
for price_id in price_ids {
257+
self.price_feeds_with_config
258+
.insert(price_id, PriceFeedClientConfig { verbose, binary });
259+
}
234260
}
235261
}
236262
Ok(ClientMessage::Unsubscribe { ids }) => {

0 commit comments

Comments
 (0)