mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
blacklist - throw errors on request/parse failure
This commit is contained in:
parent
fb1b8d42ac
commit
65aa0a1d14
@ -83,8 +83,23 @@ 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) {
|
||||
throw new Error(`BlacklistController - failed to fetch blacklist:\n${err.stack}`)
|
||||
}
|
||||
// parse response
|
||||
let rawResponse
|
||||
let phishing
|
||||
try {
|
||||
const rawResponse = await response.text()
|
||||
phishing = JSON.parse(rawResponse)
|
||||
} catch (err) {
|
||||
throw new Error(`BlacklistController - failed to parse blacklist:\n${rawResponse}`)
|
||||
}
|
||||
// update current blacklist
|
||||
this.store.updateState({ phishing })
|
||||
this._setupPhishingDetector(phishing)
|
||||
return phishing
|
||||
@ -97,9 +112,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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user