add more descriptive error handling for optional exts

This commit is contained in:
Lachlan Kermode
2019-01-17 09:40:04 +00:00
parent 08d44c79c7
commit 79af252b33
2 changed files with 29 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ function urlFromEnv(ext) {
// TODO: relegate these URLs entirely to environment variables
const EVENT_DATA_URL = urlFromEnv('EVENT_EXT');
const CATEGORY_URL = urlFromEnv('CATEGORY_EXT');
const TAG_URL = urlFromEnv('TAGS_EXT');
const TAGS_URL = urlFromEnv('TAGS_EXT');
const SOURCES_URL = urlFromEnv('SOURCES_EXT');
const NARRATIVE_URL = urlFromEnv('NARRATIVE_EXT');
const SITES_URL = urlFromEnv('SITES_EXT');
@@ -26,18 +26,6 @@ function _debugger(value) {
}
}
/*
* Create an error notification object
* Types: ['error', 'warning', 'good', 'neural']
*/
function makeError (type, id, message) {
return {
type: 'error',
id,
message: `${type} ${id}: ${message}`
}
}
export function fetchDomain () {
let notifications = []
@@ -76,16 +64,38 @@ export function fetchDomain () {
let tagsPromise = Promise.resolve([])
if (process.env.features.USE_TAGS) {
tagsPromise = fetch(TAG_URL)
.then(response => response.json())
.catch(handleError('tags'))
if (!TAGS_URL) {
notifications.push({
message: 'USE_TAGS is true, but you have not provided a TAGS_URL',
type: 'error'
})
tagsPromise = Promise.resolve({})
} else {
tagsPromise = fetch(TAGS_URL)
.then(response => {
console.log(response)
return response.json()
})
.catch(err => {
console.log(err)
return handleError('tags')
})
}
}
let sourcesPromise = Promise.resolve([])
if (process.env.features.USE_SOURCES) {
sourcesPromise = fetch(SOURCES_URL)
.then(response => response.json())
.catch(handleError('sources'))
if (!SOURCES_URL) {
notifications.push({
message: 'USE_SOURCES is true, but you have not provided a SOURCES_URL',
type: 'error'
})
tagsPromise = Prommise.resolve([])
} else {
sourcesPromise = fetch(SOURCES_URL)
.then(response => response.json())
.catch(handleError('sources'))
}
}
return Promise.all([

View File

@@ -257,7 +257,6 @@ export const selectCategories = createSelector(
categories.map(cat => {
cat.active = (!cat.hasOwnProperty('active')) ? false : cat.active
});
console.log(categories)
return categories;
}
)