Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda