Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda