Chore: throw error if undefined operatorId
This commit is contained in:
parent
8d6ed7c2a3
commit
35224e415c
2 changed files with 29 additions and 19 deletions
|
|
@ -12,6 +12,7 @@ const populateSettings = function (req, res, next) {
|
|||
state.oldVersionId = versionId
|
||||
}
|
||||
|
||||
try {
|
||||
// Clear cache every hour
|
||||
if (Date.now() - settingsCache.getTimestamp(operatorId) > SETTINGS_CACHE_REFRESH) {
|
||||
settingsCache.clear(operatorId)
|
||||
|
|
@ -32,6 +33,9 @@ const populateSettings = function (req, res, next) {
|
|||
.then(() => next())
|
||||
.catch(next)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
newSettingsLoader.load(versionId)
|
||||
.then(settings => { req.settings = settings })
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
const _ = require('lodash/fp')
|
||||
const state = require('./state')
|
||||
|
||||
const getTimestamp = (operatorId) => state.settingsCache[operatorId] ? state.settingsCache[operatorId].timestamp : null
|
||||
const getTimestamp = (operatorId) => {
|
||||
if (!operatorId) throw new Error('operatorId must not be nil or empty')
|
||||
return state.settingsCache[operatorId] ? state.settingsCache[operatorId].timestamp : null
|
||||
}
|
||||
|
||||
const getCache = (operatorId) => state.settingsCache[operatorId] ? state.settingsCache[operatorId].cache : null
|
||||
const getCache = (operatorId) => {
|
||||
if (!operatorId) throw new Error('operatorId must not be nil or empty')
|
||||
return state.settingsCache[operatorId] ? state.settingsCache[operatorId].cache : null
|
||||
}
|
||||
|
||||
const setTimestamp = (operatorId, newTimestamp) => {
|
||||
state.settingsCache = _.set([operatorId, 'timestamp'], newTimestamp, state.settingsCache)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue