Client - handle error on api calls

This commit is contained in:
Sam
2021-08-11 21:12:20 +02:00
parent cd418c9be2
commit 7df5ea9870
14 changed files with 87 additions and 15 deletions

View File

@ -1,3 +1,9 @@
export enum RootGetters {
ERROR_MESSAGE = 'ERROR_MESSAGE',
}
export enum RootMutations {
EMPTY_ERROR_MESSAGE = 'EMPTY_ERROR_MESSAGE',
SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE',
UPDATE_LANG = 'UPDATE_LANG',
}

View File

@ -0,0 +1,9 @@
import { GetterTree } from 'vuex'
import { ROOT_STORE } from '@/store/constants'
import { IRootState, IRootGetters } from '@/store/modules/root/interfaces'
export const getters: GetterTree<IRootState, IRootState> & IRootGetters = {
[ROOT_STORE.GETTERS.ERROR_MESSAGE]: (state: IRootState) => {
return state.errorMessage
},
}

View File

@ -1,4 +1,5 @@
import { Module, ModuleTree } from 'vuex'
import { getters } from '@/store/modules/root/getters'
import { IRootState } from '@/store/modules/root/interfaces'
import { mutations } from '@/store/modules/root/mutations'
import { state } from '@/store/modules/root/state.ts'
@ -10,6 +11,7 @@ const modules: ModuleTree<IRootState> = {
const root: Module<IRootState, IRootState> = {
state,
getters,
mutations,
modules,
}

View File

@ -1,5 +1,11 @@
import { ROOT_STORE } from '@/store/constants'
export interface IRootState {
root: boolean
language: string
errorMessage: string | null
}
export interface IRootGetters {
[ROOT_STORE.GETTERS.ERROR_MESSAGE](state: IRootState): string | null
}

View File

@ -4,6 +4,15 @@ import { IRootState } from '@/store/modules/root/interfaces'
import { TRootMutations } from '@/store/modules/root/types'
export const mutations: MutationTree<IRootState> & TRootMutations = {
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE](state: IRootState) {
state.errorMessage = null
},
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGE](
state: IRootState,
errorMessage: string
) {
state.errorMessage = errorMessage
},
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: IRootState, language: string) {
state.language = language
},

View File

@ -2,5 +2,7 @@ import { ROOT_STORE } from '@/store/constants'
import { IRootState } from '@/store/modules/root/interfaces'
export type TRootMutations<S = IRootState> = {
[ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGE](state: S): void
[ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGE](state: S, errorMessage: string): void
[ROOT_STORE.MUTATIONS.UPDATE_LANG](state: S, language: string): void
}