Cleanup configuration loading a bit

- Move configuration hash clearing to RESET
- Dispatch STOP_UPDATES and RESET actions from LOAD_CONFIGURATION action
- Make exception handling simpler
This commit is contained in:
James Lyne 2021-09-08 14:35:44 +01:00
parent 80a60010a3
commit 1b9a3e4f1a
4 changed files with 13 additions and 29 deletions

View File

@ -74,8 +74,6 @@ export default defineComponent({
showSplash(!loadingAttempts.value);
loading.value = true;
await store.dispatch(ActionTypes.STOP_UPDATES, undefined);
store.commit(MutationTypes.RESET, undefined);
await store.dispatch(ActionTypes.LOAD_CONFIGURATION, undefined);
await store.dispatch(ActionTypes.START_UPDATES, undefined);
@ -89,23 +87,15 @@ export default defineComponent({
}
});
} catch(e: any) {
//Request was aborted, probably because another server was selected before the request finished. Don't retry
if(e instanceof DOMException && e.name === 'AbortError') {
return;
// Don't retry if request was aborted or logging in is required
if(!(e instanceof DOMException && e.name === 'AbortError') && !loginRequired.value) {
const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`;
console.error(`${error}:`, e);
showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value);
clearTimeout(loadingTimeout);
loadingTimeout = setTimeout(() => loadConfiguration(), 1000);
}
//Logging in is required
if(loginRequired.value) {
return;
}
//Any other errors
const error = `Failed to load server configuration for '${store.state.currentServer!.id}'`;
console.error(`${error}:`, e);
showSplashError(`${error}\n${e}`, false, ++loadingAttempts.value);
clearTimeout(loadingTimeout);
loadingTimeout = setTimeout(() => loadConfiguration(), 1000);
} finally {
loading.value = false;
}
@ -212,7 +202,7 @@ export default defineComponent({
} else {
store.commit(MutationTypes.HIDE_UI_MODAL, 'login');
}
})
});
onMounted(() => loadConfiguration());
onBeforeUnmount(() => {

View File

@ -85,9 +85,9 @@ export interface Actions {
}
export const actions: ActionTree<State, State> & Actions = {
async [ActionTypes.LOAD_CONFIGURATION]({commit, state}): Promise<void> {
//Clear any existing has to avoid triggering a second config load, after this load changes the hash
commit(MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH, undefined);
async [ActionTypes.LOAD_CONFIGURATION]({commit, state, dispatch}): Promise<void> {
await dispatch(ActionTypes.STOP_UPDATES, undefined);
commit(MutationTypes.RESET, undefined);
if(!state.currentServer) {
console.warn('No current server');

View File

@ -19,7 +19,6 @@ export enum MutationTypes {
SET_SERVER_CONFIGURATION = 'setServerConfiguration',
SET_SERVER_CONFIGURATION_HASH = 'setServerConfigurationHash',
CLEAR_SERVER_CONFIGURATION_HASH = 'clearServerConfigurationHash',
SET_SERVER_MESSAGES = 'setServerMessages',
SET_WORLDS = 'setWorlds',
SET_COMPONENTS = 'setComponents',

View File

@ -53,7 +53,6 @@ export type Mutations<S = State> = {
[MutationTypes.INIT](state: S, config: LiveAtlasGlobalConfig): void
[MutationTypes.SET_SERVER_CONFIGURATION](state: S, config: LiveAtlasServerConfig): void
[MutationTypes.SET_SERVER_CONFIGURATION_HASH](state: S, hash: number): void
[MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH](state: S): void
[MutationTypes.SET_SERVER_MESSAGES](state: S, messages: LiveAtlasServerMessageConfig): void
[MutationTypes.SET_WORLDS](state: S, worlds: Array<LiveAtlasWorldDefinition>): void
[MutationTypes.SET_COMPONENTS](state: S, components: LiveAtlasPartialComponentConfig | LiveAtlasComponentConfig): void
@ -188,11 +187,6 @@ export const mutations: MutationTree<State> & Mutations = {
state.configurationHash = hash;
},
// Sets configuration hash
[MutationTypes.CLEAR_SERVER_CONFIGURATION_HASH](state: State) {
state.configurationHash = undefined;
},
// Sets messages from the initial config fetch
[MutationTypes.SET_SERVER_MESSAGES](state: State, messages: LiveAtlasServerMessageConfig) {
state.messages = Object.assign(state.messages, messages);
@ -650,6 +644,7 @@ export const mutations: MutationTree<State> & Mutations = {
state.currentWorldState.raining = false;
state.currentWorldState.thundering = false;
state.configurationHash = undefined;
state.configuration.title = '';
state.components.markers.showLabels= false;