🥅 Catch error caused by empty config

This commit is contained in:
Alicia Sykes 2024-04-27 00:32:01 +01:00
parent 4594c99b57
commit 9e6fb17d93
2 changed files with 13 additions and 5 deletions

View File

@ -116,7 +116,8 @@ export default {
}, },
mounted() { mounted() {
const jsonData = { ...this.config }; const jsonData = { ...this.config };
jsonData.sections = jsonData.sections.map(({ filteredItems, ...section }) => section); jsonData.sections = (jsonData.sections || []).map(({ filteredItems, ...section }) => section);
if (!jsonData.pageInfo) jsonData.pageInfo = { title: 'Dashy' };
this.jsonData = jsonData; this.jsonData = jsonData;
if (!this.allowWriteToDisk) this.saveMode = 'local'; if (!this.allowWriteToDisk) this.saveMode = 'local';
}, },

View File

@ -44,6 +44,12 @@ const {
CRITICAL_ERROR_MSG, CRITICAL_ERROR_MSG,
} = Keys; } = Keys;
const emptyConfig = {
appConfig: {},
pageInfo: { title: 'Dashy' },
sections: [],
};
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
config: {}, // The current config being used, and rendered to the UI config: {}, // The current config being used, and rendered to the UI
@ -335,7 +341,7 @@ const store = new Vuex.Store({
data = yaml.load(response.data); data = yaml.load(response.data);
} catch (parseError) { } catch (parseError) {
commit(CRITICAL_ERROR_MSG, `Failed to parse YAML: ${parseError.message}`); commit(CRITICAL_ERROR_MSG, `Failed to parse YAML: ${parseError.message}`);
return {}; return { ...emptyConfig };
} }
// Replace missing root properties with empty objects // Replace missing root properties with empty objects
if (!data.appConfig) data.appConfig = {}; if (!data.appConfig) data.appConfig = {};
@ -357,7 +363,7 @@ const store = new Vuex.Store({
} else { } else {
commit(CRITICAL_ERROR_MSG, `Failed to fetch configuration: ${fetchError.message}`); commit(CRITICAL_ERROR_MSG, `Failed to fetch configuration: ${fetchError.message}`);
} }
return {}; return { ...emptyConfig };
} }
}, },
/** /**
@ -368,6 +374,7 @@ const store = new Vuex.Store({
*/ */
async [INITIALIZE_CONFIG]({ commit, state }, subConfigId) { async [INITIALIZE_CONFIG]({ commit, state }, subConfigId) {
const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG); const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
commit(SET_IS_USING_LOCAL_CONFIG, false); commit(SET_IS_USING_LOCAL_CONFIG, false);
if (!subConfigId) { // Use root config as config if (!subConfigId) { // Use root config as config
commit(SET_CONFIG, rootConfig); commit(SET_CONFIG, rootConfig);
@ -396,7 +403,7 @@ const store = new Vuex.Store({
if (!subConfigPath) { if (!subConfigPath) {
commit(CRITICAL_ERROR_MSG, `Unable to find config for '${subConfigId}'`); commit(CRITICAL_ERROR_MSG, `Unable to find config for '${subConfigId}'`);
return null; return { ...emptyConfig };
} }
axios.get(subConfigPath).then((response) => { axios.get(subConfigPath).then((response) => {
@ -428,7 +435,7 @@ const store = new Vuex.Store({
commit(CRITICAL_ERROR_MSG, `Unable to load config from '${subConfigPath}'`, err); commit(CRITICAL_ERROR_MSG, `Unable to load config from '${subConfigPath}'`, err);
}); });
} }
return null; return { ...emptyConfig };
}, },
}, },
modules: {}, modules: {},