export default {
    state: {
        errorCount: 0,
        errorRepresentation: null,
    },
    getters: {
        getErrorRepresentation(state) {
            return state.errorRepresentation;
        },
        getErrorCount(state) {
            return state.errorCount;
        }
    },
    mutations: {
        setErrorMessage(state, message) {
            state.errorRepresentation = message;
            state.errorCount += 1;
        },
    },
    actions: {
        setErrorMessage(context, errorMessage) {
            debugger;

            if (errorMessage.error.ignoreUnhandledRejection) {
                return
            }
            context.commit('setErrorMessage', {shortForm: `${errorMessage.error}`, message: `${errorMessage.error.response?.data?.error} - ${errorMessage.error.response?.data?.message}`, detail: `${errorMessage.error.stack}`});
            throw { source: errorMessage.error, ignoreUnhandledRejection: true };
        },
    }
}