From 85295ea62c27ffdc7893ef4a8a4e21d3abd83126 Mon Sep 17 00:00:00 2001 From: Zoran Joka Date: Wed, 10 Oct 2018 10:55:11 +0200 Subject: [PATCH] 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 --- lib/ofac/update.js | 7 ++++++- lib/poller.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ofac/update.js b/lib/ofac/update.js index b6de2eac..35271370 100644 --- a/lib/ofac/update.js +++ b/lib/ofac/update.js @@ -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)) diff --git a/lib/poller.js b/lib/poller.js index 0d4cdeeb..64681bdb 100644 --- a/lib/poller.js +++ b/lib/poller.js @@ -29,6 +29,7 @@ function reload (__settings) { _settings = __settings _pi = plugins(_settings) logger.debug('settings reloaded in poller') + updateAndLoadSanctions() } function pi () { return _pi }