Vuex axios call can't handle 422 response

I’m trying to handle 422 response from API in case data is invalid when making 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 request is successful all works fine and I get response, however if response is 422 it doesn’t fall throw exception and 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?

147 thoughts on “Vuex axios call can't handle 422 response”

  1. 124819 316005Wonderful beat ! I would like to apprentice whilst you amend your web internet site, how can i subscribe for a blog site? The account helped me a applicable deal. I had been tiny bit acquainted of this your broadcast provided shiny transparent notion. 553907

    Reply

Leave a Comment