Ensure etags.json can update when empty (#182)

* Ensure etags.json can update when empty

* Update and load etags on settings change

* Handle exception in catch block
This commit is contained in:
Zoran Joka 2018-10-10 10:55:11 +02:00 committed by Josh Harvey
parent f4fc9d6328
commit 85295ea62c
2 changed files with 7 additions and 1 deletions

View file

@ -6,6 +6,7 @@ const path = require('path')
const util = require('util')
const options = require('../options')
const _ = require('lodash/fp')
const logger = require('../logger')
const DOWNLOAD_DIR = path.resolve('/tmp')
@ -114,7 +115,11 @@ function update () {
})
.then(() => {
const promiseOldEtags = readFile(OFAC_ETAGS_FILE, {encoding: 'utf-8'})
.then(json => JSON.parse(json) || {})
.then(json => JSON.parse(json))
.catch(_ => {
logger.error('Can\'t parse etags.json, getting new data...')
return {}
})
const promiseNewEtags = Promise.resolve(options.ofacSources || [])
.then(sources => Promise.all(_.map(promiseGetEtag, sources))