Make sure exchange API response format is valid before using it

This commit is contained in:
nymkappa
2022-12-01 12:05:23 +01:00
parent 2b411aad0a
commit a671bfc226
6 changed files with 33 additions and 6 deletions

View File

@@ -13,7 +13,11 @@ class GeminiApi implements PriceFeed {
public async $fetchPrice(currency): Promise<number> {
const response = await query(this.url + currency);
return response ? parseInt(response['last'], 10) : -1;
if (response && response['last']) {
return parseInt(response['last'], 10);
} else {
return -1;
}
}
public async $fetchRecentPrice(currencies: string[], type: 'hour' | 'day'): Promise<PriceHistory> {