Client - handle error on api calls
This commit is contained in:
@ -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',
|
||||
}
|
||||
|
9
fittrackee_client/src/store/modules/root/getters.ts
Normal file
9
fittrackee_client/src/store/modules/root/getters.ts
Normal 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
|
||||
},
|
||||
}
|
@ -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,
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
},
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user