Not 100% sure but a try/catch block in the component should work.
Jan 13, 2021
7
Level 5
How can I throw the error from axios (in vuex actions state) and catch it in the compoent ???
I am using axios 0.21.1 in vuex actions to get the grid data.
The problem is I don't know how to throw the response back to the component:
actions: {
loadGridData({ commit, getters }, url) {
axios.get(url + getters.gridQueries, {
headers: {Authorization: 'Bearer ' + access_token}
}).then(function (response) {
commit('addGridData', response.data);
}).catch(function (error) {
throw new Error(error.response.data);
})
}
}
On the component
this.$store.dispatch('loadGridData', this.url).catch(error => {
this.$swal('Server Error!', error, 'error');
});
I am getting in consonsole:
Uncaught (in promise) Error: test error
where "test error" is a message generated by me with a 500 response to test the catch errors in laravel.
return response()->json('test error',500);
How can I throw the error from axios (in vuex actions state) and catch it in the compoent ???
Please or to participate in this conversation.