I have this method:
service
const errorData = {"message":"Error", "data": []};
list(url) {
return new Promise((resolve) => {
axios.get(url).then((response) => {
resolve(response.data);
}).catch((error) => {
resolve(errorData)
});
})
},
module store
state: {
list: []
},
getters: {
list: state => state.list,
},
mutations: {
LIST(state, payload) {
state.list = payload || [];
},
}
actions: {
list({ commit }) {
commit('LIST', []);
return service
.list('api/list')
.then((list) => {
commit('LIST', list);
});
},
}
list component
this.$store.dispatch(`module/store/list`).then(() => {
setTimeout(() => {
var message = this.$store.getters['module/list'].message;
this.$refs.inform.open('Error', message).then(() => {
this.$router.push ({ path: "/" });
});
}, 1000);
})
Note: response.data from successful API call return an object with the same structure as errorData.
When I turn off the server where it calls the API methods, Axios catches the error if there are any, but something throws an error and halts the app's current operation "net::ERR_CONNECTION_REFUSED". I don't know where to catch this. I've tried appending catches on all methods using Axios related to this but then I couldn't catch the error. It should stop when the error is initially caught by Axios without stopping the app's operation.
I'd really appreciate any advice that can be given to resolve this problem of mine. Thank you.