diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-10-30 09:57:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 09:57:51 +0800 |
commit | 73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f (patch) | |
tree | 51b163f772d253b8e56588fd254ca918a8b058a2 /app/scripts/controllers | |
parent | 310229d22e5e916e8d6e3b1a469b9b196e0f70c2 (diff) | |
parent | 7ae5a23b6c0e9839f63bba52ab5bf7da00bef173 (diff) | |
download | tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.gz tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.bz2 tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.lz tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.xz tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.tar.zst tangerine-wallet-browser-73eeeda2157e8a7ef61ff1f1fd0f4b94821f2e6f.zip |
Merge pull request #5560 from MetaMask/sentry-enhancements2
Sentry - various enhancements to help debugging (alternate)
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/blacklist.js | 25 | ||||
-rw-r--r-- | app/scripts/controllers/currency.js | 30 |
2 files changed, 49 insertions, 6 deletions
diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js index 89c7cc888..e55b09d03 100644 --- a/app/scripts/controllers/blacklist.js +++ b/app/scripts/controllers/blacklist.js @@ -83,8 +83,25 @@ class BlacklistController { * */ async updatePhishingList () { - const response = await fetch('https://api.infura.io/v2/blacklist') - const phishing = await response.json() + // make request + let response + try { + response = await fetch('https://api.infura.io/v2/blacklist') + } catch (err) { + log.error(new Error(`BlacklistController - failed to fetch blacklist:\n${err.stack}`)) + return + } + // parse response + let rawResponse + let phishing + try { + const rawResponse = await response.text() + phishing = JSON.parse(rawResponse) + } catch (err) { + log.error(new Error(`BlacklistController - failed to parse blacklist:\n${rawResponse}`)) + return + } + // update current blacklist this.store.updateState({ phishing }) this._setupPhishingDetector(phishing) return phishing @@ -97,9 +114,9 @@ class BlacklistController { */ scheduleUpdates () { if (this._phishingUpdateIntervalRef) return - this.updatePhishingList().catch(log.warn) + this.updatePhishingList() this._phishingUpdateIntervalRef = setInterval(() => { - this.updatePhishingList().catch(log.warn) + this.updatePhishingList() }, POLLING_INTERVAL) } diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js index 1e866d2c9..fce65fd9c 100644 --- a/app/scripts/controllers/currency.js +++ b/app/scripts/controllers/currency.js @@ -133,18 +133,40 @@ class CurrencyController { try { currentCurrency = this.getCurrentCurrency() nativeCurrency = this.getNativeCurrency() + // select api let apiUrl if (nativeCurrency === 'ETH') { + // ETH apiUrl = `https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}` } else { + // ETC apiUrl = `https://min-api.cryptocompare.com/data/price?fsym=${nativeCurrency.toUpperCase()}&tsyms=${currentCurrency.toUpperCase()}` } - const response = await fetch(apiUrl) - const parsedResponse = await response.json() + // attempt request + let response + try { + response = await fetch(apiUrl) + } catch (err) { + log.error(new Error(`CurrencyController - Failed to request currency from Infura:\n${err.stack}`)) + return + } + // parse response + let rawResponse + let parsedResponse + try { + rawResponse = await response.text() + parsedResponse = JSON.parse(rawResponse) + } catch (err) { + log.error(new Error(`CurrencyController - Failed to parse response "${rawResponse}"`)) + return + } + // set conversion rate if (nativeCurrency === 'ETH') { + // ETH this.setConversionRate(Number(parsedResponse.bid)) this.setConversionDate(Number(parsedResponse.timestamp)) } else { + // ETC if (parsedResponse[currentCurrency.toUpperCase()]) { this.setConversionRate(Number(parsedResponse[currentCurrency.toUpperCase()])) this.setConversionDate(parseInt((new Date()).getTime() / 1000)) @@ -154,9 +176,13 @@ class CurrencyController { } } } catch (err) { + // reset current conversion rate log.warn(`MetaMask - Failed to query currency conversion:`, nativeCurrency, currentCurrency, err) this.setConversionRate(0) this.setConversionDate('N/A') + // throw error + log.error(new Error(`CurrencyController - Failed to query rate for currency "${currentCurrency}":\n${err.stack}`)) + return } } |