mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-24 01:12:06 +03:00
🥅 Catch error caused by empty config
This commit is contained in:
parent
4594c99b57
commit
9e6fb17d93
@ -116,7 +116,8 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
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;
|
||||
if (!this.allowWriteToDisk) this.saveMode = 'local';
|
||||
},
|
||||
|
15
src/store.js
15
src/store.js
@ -44,6 +44,12 @@ const {
|
||||
CRITICAL_ERROR_MSG,
|
||||
} = Keys;
|
||||
|
||||
const emptyConfig = {
|
||||
appConfig: {},
|
||||
pageInfo: { title: 'Dashy' },
|
||||
sections: [],
|
||||
};
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
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);
|
||||
} catch (parseError) {
|
||||
commit(CRITICAL_ERROR_MSG, `Failed to parse YAML: ${parseError.message}`);
|
||||
return {};
|
||||
return { ...emptyConfig };
|
||||
}
|
||||
// Replace missing root properties with empty objects
|
||||
if (!data.appConfig) data.appConfig = {};
|
||||
@ -357,7 +363,7 @@ const store = new Vuex.Store({
|
||||
} else {
|
||||
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) {
|
||||
const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
|
||||
|
||||
commit(SET_IS_USING_LOCAL_CONFIG, false);
|
||||
if (!subConfigId) { // Use root config as config
|
||||
commit(SET_CONFIG, rootConfig);
|
||||
@ -396,7 +403,7 @@ const store = new Vuex.Store({
|
||||
|
||||
if (!subConfigPath) {
|
||||
commit(CRITICAL_ERROR_MSG, `Unable to find config for '${subConfigId}'`);
|
||||
return null;
|
||||
return { ...emptyConfig };
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
return null;
|
||||
return { ...emptyConfig };
|
||||
},
|
||||
},
|
||||
modules: {},
|
||||
|
Loading…
Reference in New Issue
Block a user