I'm trying to handle 422 response from my API in case data is invalid when making an async Axios call.
In a component, I have a method like:
async saveChanges() {
this.isSaving = true;
await this.$store.dispatch('updateSettings', this.formData);
this.isSaving = false;
}
And in my actions like this:
let response;
try {
response = await axios.put('/api/settings', settings);
console.log(response);
} catch (e) {
console.log('error');
console.log(e);
}
If the request is successful, everything works fine, and I get a response. However, if the response status code is 422, it doesn't fail or throw an exception, and the response is empty. I've tried with .then(()).catch(())
, but no luck either as I need it to be async.
Any suggestions what I might be doing wrong?