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

This commit is contained in:
Ali Behjati 2022-05-05 15:40:35 +04:30 committed by GitHub
parent 7b9d5b1c22
commit 11e15c96b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -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>&..");