From 79af252b33f943e9c404e1f5339c99de549486cd Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Thu, 17 Jan 2019 09:40:04 +0000 Subject: [PATCH] add more descriptive error handling for optional exts --- src/actions/index.js | 48 +++++++++++++++++++++++++----------------- src/selectors/index.js | 1 - 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/actions/index.js b/src/actions/index.js index c8bdf0e..9642de9 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -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([ diff --git a/src/selectors/index.js b/src/selectors/index.js index 2367b35..e6562ad 100644 --- a/src/selectors/index.js +++ b/src/selectors/index.js @@ -257,7 +257,6 @@ export const selectCategories = createSelector( categories.map(cat => { cat.active = (!cat.hasOwnProperty('active')) ? false : cat.active }); - console.log(categories) return categories; } )