app - warn on fetch errors instead of spamming sentry

This commit is contained in:
kumavis 2018-04-03 10:33:10 -07:00
parent 3e4b11e0d7
commit ecbab14cae
5 changed files with 37 additions and 44 deletions

View File

@ -41,9 +41,9 @@ class BlacklistController {
scheduleUpdates () {
if (this._phishingUpdateIntervalRef) return
this.updatePhishingList()
this.updatePhishingList().catch(log.warn)
this._phishingUpdateIntervalRef = setInterval(() => {
this.updatePhishingList()
this.updatePhishingList().catch(log.warn)
}, POLLING_INTERVAL)
}
@ -57,4 +57,3 @@ class BlacklistController {
}
module.exports = BlacklistController

View File

@ -43,20 +43,18 @@ class CurrencyController {
this.store.updateState({ conversionDate })
}
updateConversionRate () {
const currentCurrency = this.getCurrentCurrency()
return fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}`)
.then(response => response.json())
.then((parsedResponse) => {
await updateConversionRate () {
try {
const currentCurrency = this.getCurrentCurrency()
const response = await fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}`)
const parsedResponse = await response.json()
this.setConversionRate(Number(parsedResponse.bid))
this.setConversionDate(Number(parsedResponse.timestamp))
}).catch((err) => {
if (err) {
console.warn(`MetaMask - Failed to query currency conversion:`, currentCurrency, err)
this.setConversionRate(0)
this.setConversionDate('N/A')
}
})
} catch (err) {
console.warn(`MetaMask - Failed to query currency conversion:`, currentCurrency, err)
this.setConversionRate(0)
this.setConversionDate('N/A')
}
}
scheduleConversionInterval () {

View File

@ -19,15 +19,13 @@ class InfuraController {
// Responsible for retrieving the status of Infura's nodes. Can return either
// ok, degraded, or down.
checkInfuraNetworkStatus () {
return fetch('https://api.infura.io/v1/status/metamask')
.then(response => response.json())
.then((parsedResponse) => {
this.store.updateState({
infuraNetworkStatus: parsedResponse,
})
return parsedResponse
})
async checkInfuraNetworkStatus () {
const response = await fetch('https://api.infura.io/v1/status/metamask')
const parsedResponse = await response.json()
this.store.updateState({
infuraNetworkStatus: parsedResponse,
})
return parsedResponse
}
scheduleInfuraNetworkCheck () {
@ -35,7 +33,7 @@ class InfuraController {
clearInterval(this.conversionInterval)
}
this.conversionInterval = setInterval(() => {
this.checkInfuraNetworkStatus()
this.checkInfuraNetworkStatus().catch(log.warn)
}, POLLING_INTERVAL)
}
}

View File

@ -45,18 +45,19 @@ class ShapeshiftController {
})
}
updateTx (tx) {
const url = `https://shapeshift.io/txStat/${tx.depositAddress}`
return fetch(url)
.then((response) => {
return response.json()
}).then((json) => {
async updateTx (tx) {
try {
const url = `https://shapeshift.io/txStat/${tx.depositAddress}`
const response = await fetch(url)
const json = await response.json()
tx.response = json
if (tx.response.status === 'complete') {
tx.time = new Date().getTime()
}
return tx
})
} catch (err) {
log.warn(err)
}
}
saveTx (tx) {

View File

@ -25,18 +25,15 @@ const getMessage = (locale, key, substitutions) => {
return phrase
}
function fetchLocale (localeName) {
return new Promise((resolve, reject) => {
return fetch(`./_locales/${localeName}/messages.json`)
.then(response => response.json())
.then(
locale => resolve(locale),
error => {
log.error(`failed to fetch ${localeName} locale because of ${error}`)
resolve({})
}
)
})
async function fetchLocale (localeName) {
try {
const response = await fetch(`./_locales/${localeName}/messages.json`)
const locale = await response.json()
return locale
} catch (error) {
log.error(`failed to fetch ${localeName} locale because of ${error}`)
return {}
}
}
module.exports = {