Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Handling exceptions in Vuex mutators

I came across this scenario today, and would like to know the best approach to handling it.

The Vuex action uses Axios to post a record to the back end, catching any exceptions. Once the POST request returns, a mutator is called with the returned data. The issue is if an exception occurs in the mutator, it is not caught by error handling in the action, or the calling component.

Example If the spread operator within the mutation is removed, an "object expected, got array" exception would be thrown, which I would expect to be caught within the .catch() function of the action call within the component, but it is not. Why and how can this be handled? If the solution to wrap the action call in an additional try/catch?

Action

async saveRecords({ commit }, records) {
        return new Promise((resolve, reject) => {
            axios.post("/records", records)
                .then((res) => {
                    commit('addRecords', res.data.records)
                    resolve();
                })
                .catch((error) => {
                    reject(error);
                })
        })
    }

Mutation

addCase: function (state, caseRecord) {
    console.log("inside mutation")
    state.cases.push(...caseRecord) 
},

Component

this.saveRecords(records)
    .catch((e) => {
          // IExpecting exception from mutation to be caught here
        })
      });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!