From bc43caaf964a571a093ea8fc592a5ccbf549c6a3 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 28 May 2022 15:48:10 +0100 Subject: [PATCH] :goal_net: Catch errors caused by null config (#682) Fixes #682 --- src/router.js | 12 +++++++++++- src/store.js | 7 +++++-- src/utils/ConfigAccumalator.js | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/router.js b/src/router.js index 7551c9d3..6606d85d 100644 --- a/src/router.js +++ b/src/router.js @@ -19,7 +19,17 @@ import { metaTagData, startingView, routePaths } from '@/utils/defaults'; import ErrorHandler from '@/utils/ErrorHandler'; // Import data from users conf file. Note that rebuild is required for this to update. -import { pages, pageInfo, appConfig } from '../public/conf.yml'; +import conf from '../public/conf.yml'; + +if (!conf) { + ErrorHandler('You\'ve not got any data in your config file yet.'); +} + +// Assign top-level config fields, check not null +const config = conf || {}; +const pages = config.pages || []; +const pageInfo = config.pageInfo || {}; +const appConfig = config.appConfig || {}; Vue.use(Router); const progress = new Progress({ color: 'var(--progress-bar)' }); diff --git a/src/store.js b/src/store.js index 1fa246cd..4eea3763 100644 --- a/src/store.js +++ b/src/store.js @@ -56,9 +56,11 @@ const store = new Vuex.Store({ return state.config; }, pageInfo(state) { + if (!state.config) return {}; return state.config.pageInfo || {}; }, appConfig(state) { + if (!state.config) return {}; return state.config.appConfig || {}; }, sections(state) { @@ -140,8 +142,9 @@ const store = new Vuex.Store({ state.config = config; }, [SET_REMOTE_CONFIG](state, config) { - if (!config.appConfig) config.appConfig = {}; - state.remoteConfig = config; + const notNullConfig = config || {}; + if (!notNullConfig.appConfig) notNullConfig.appConfig = {}; + state.remoteConfig = notNullConfig; }, [SET_LANGUAGE](state, lang) { const newConfig = state.config; diff --git a/src/utils/ConfigAccumalator.js b/src/utils/ConfigAccumalator.js index 3c07c238..76fefb62 100644 --- a/src/utils/ConfigAccumalator.js +++ b/src/utils/ConfigAccumalator.js @@ -31,7 +31,11 @@ export default class ConfigAccumulator { appConfig() { let appConfigFile = {}; // Set app config from file - if (this.conf) appConfigFile = this.conf.appConfig || buildConf.appConfig || {}; + if (this.conf && this.conf.appConfig) { + appConfigFile = this.conf.appConfig; + } else if (buildConf && buildConf.appConfig) { + appConfigFile = buildConf.appConfig; + } // Fill in defaults if anything missing let usersAppConfig = defaultAppConfig; if (localStorage[localStorageKeys.APP_CONFIG]) {