I am trying to work out on how to handle errors when using axios. Please see the code below:
//Admin.vue
methods: {
saveClicked: function(){
updateConfig(this.editedConfig)
.then(response => {
console.log("in here");
console.log(response);
this.info.showAlert = true;
this.info.message = "Successfully updated config!!"
this.info.alertType = "success";
this.showJsonEditor = !this.showJsonEditor;
})
.catch(error => {
this.info.showAlert = true;
this.info.message = "Failed to update config, please try again later"
this.info.alertType = "error";
});
}
}
//network.js
function updateConfig(editedConfig){
return axios.put(URL,editedConfig, {
headers: {
"Content-type": "application/json"
}
})
.then(response => response)
.catch(error => error);
}
When the requests is successful, everything is fine. I get my alert saying all is good.
I forced my backend to return an error for every request so i can simulate error behaviour in my Vue application and this is what i observed:
Even when error is received. The the program is going through then() in Admin.vuecheck the image below:
What have i missed?
