Преглед изворни кода

On not found price id return list of not found ids (#200)

Ali Behjati пре 3 година
родитељ
комит
11e15c96b0
1 измењених фајлова са 9 додато и 2 уклоњено
  1. 9 2
      third_party/pyth/price-service/src/rest.ts

+ 9 - 2
third_party/pyth/price-service/src/rest.ts

@@ -105,12 +105,14 @@ export class RestAPI {
 
       let responseJson = [];
 
+      let notFoundIds: string[] = [];
+
       for (let id of priceIds) {
         let latestPriceInfo = this.priceFeedVaaInfo.getLatestPriceInfo(id);
 
         if (latestPriceInfo === undefined) {
-          res.status(StatusCodes.BAD_REQUEST).send(`Price Feed with id ${id} not found`);
-          return;
+          notFoundIds.push(id);
+          continue;
         }
 
         const freshness: DurationInSec = (new Date).getTime() / 1000 - latestPriceInfo.receiveTime;
@@ -119,6 +121,11 @@ export class RestAPI {
         responseJson.push(latestPriceInfo.priceFeed.toJson());
       }
 
+      if (notFoundIds.length > 0) {
+        res.status(StatusCodes.BAD_REQUEST).send(`Price Feeds with ids ${notFoundIds.join(', ')} not found`);
+        return;
+      }
+
       res.json(responseJson);
     });
     endpoints.push("latest_price_feed?id[]=<price_feed_id>&id[]=<price_feed_id_2>&..");