I recently implemented transformRequest and transformResponse functions to display a loader while my data is rendering. However, after adding these functions, I noticed that my POST and PATCH requests are not functioning properly. There are no error messages in the console, but whenever I try to modify an entity using a PATCH request, nothing happens. Removing the transformRequest function allows me to successfully send POST and PATCH requests.
Could someone please help me identify what went wrong?
UPDATE! Below is the excerpt from http/index.js:
...
transformRequest(data) {
console.log(data); // returns undefined
store.dispatch('loadingData');
console.log(data) // returns undefined
return console.log(JSON.stringify(data)); // returns undefined
},
transformResponse(data) {
store.dispatch('finishLoadingData');
const parsedData = JSON.parse(data);
if (parsedData.error === 'Access denied') {
cookies.remove('access_token');
window.location = `${config.mainSite}/login`;
}
return parsedData;
},
...
Here's the information related to the store:
export default {
state: {
loading: false,
},
actions: {
loadingData({ commit }) {
commit('LOADING_DATA');
},
finishLoadingData({ commit }) {
commit('FINISH_LOADING_DATA');
},
},
mutations: {
LOADING_DATA(state) {
state.loading = true;
},
FINISH_LOADING_DATA(state) {
state.loading = false;
},
},
getters: {
getLoading(state) {
return state.loading;
},
},
};