aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-10-19 16:58:19 +0800
committerkumavis <aaron@kumavis.me>2018-10-19 16:58:19 +0800
commit2394881511928e414ca99cac2a46f30a7703ae91 (patch)
tree7844d559f08fa76728df253c5edb62caaa10a6bf /app
parent65aa0a1d14b0b18d77b537b216d03ce5d9fca725 (diff)
downloadtangerine-wallet-browser-2394881511928e414ca99cac2a46f30a7703ae91.tar.gz
tangerine-wallet-browser-2394881511928e414ca99cac2a46f30a7703ae91.tar.zst
tangerine-wallet-browser-2394881511928e414ca99cac2a46f30a7703ae91.zip
currency - throw errors on failure
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/currency.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js
index d5bc5fe2b..619c515fa 100644
--- a/app/scripts/controllers/currency.js
+++ b/app/scripts/controllers/currency.js
@@ -107,14 +107,28 @@ class CurrencyController {
let currentCurrency
try {
currentCurrency = this.getCurrentCurrency()
- const response = await fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}`)
- const parsedResponse = await response.json()
+ let response
+ try {
+ response = await fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}`)
+ } catch (err) {
+ throw new Error(`CurrencyController - Failed to request currency from Infura:\n${err.stack}`)
+ }
+ let rawResponse
+ let parsedResponse
+ try {
+ rawResponse = await response.text()
+ parsedResponse = JSON.parse(rawResponse)
+ } catch () {
+ throw new Error(`CurrencyController - Failed to parse response "${rawResponse}"`)
+ }
this.setConversionRate(Number(parsedResponse.bid))
this.setConversionDate(Number(parsedResponse.timestamp))
} catch (err) {
- log.warn(`MetaMask - Failed to query currency conversion:`, currentCurrency, err)
+ // reset current conversion rate
this.setConversionRate(0)
this.setConversionDate('N/A')
+ // throw error
+ throw new Error(`CurrencyController - Failed to query rate for currency "${currentCurrency}":\n${err.stack}`)
}
}