Hello, I am developing an application in Vue.js, Nativescript and Vuex , when making an ajax request in an action return a promise to handle asynchrony the problem is that when an error is generated this It is not captured at the moment of calling the method but when everything is working well.
in the action method place a url that does not exist to lead to the error but does not pass through this, which you think it may be.
action method
CrearUsuario(context,objeto){
console.log("el valor de objeto antes de enviar es " + JSON.stringify(objeto));
return new Promise((resolve,reject)=>{ //usando promesas para controlar asincronia de peticion
http.request({
url : servidor + "/api/personas/thisUrlDoesntExist",
method : "POST",
headers : { "Content-Type": "application/json" },
content : JSON.stringify({objeto })
}).then( response => {
console.log("estamos usando json");
console.log("el valor total es " + JSON.stringify(response));
var result = response.content.toJSON();
context.commit('SetJson',result);
resolve(response);
},
error => {
//console.error(error);
reject(error);
});
})
}
code when calling action method
Insertar(){
var objeto={
":PA_PAIS_ID" : this.form.txtpaisId,
":PE_NOMBRE" : this.form.txtNombre,
":PE_CORREO" : this.form.txtCorreo,
":PE_CLAVE" : this.form.txtpass
}
this.$store.dispatch('CrearUsuario',objeto).then(response => {
//al ser success funciona perfecto y pasa por aqui
console.log("terminamos la peticion");
this.isBusy=false;
},
// al manejar error no funciona no muestra mensaje
error=>{
console.log("error en peticion " + error );
this.isBusy=false;
}
);
},
Finally it is worth mentioning that I am using the Nativescript http module to make the request to the server.