Throw error in Client

Hi,

I can’t get error on client when I use Meteor.call().

The variable err always set with undefined.

Example:

In Client:

Template.agendamentos.events({
  'click #cancelarCompromisso': function() {
     Meteor.call("cancel", id, function (err, res) {
       if( err){
         console.log("Error");
       }else{
         console.log("Works");
       }  
     });
   }
});

In Server:

Meteor.methods({
  cancel: function(id){
	Register.remove(appointment._id, function(err, res){
		if (err) {
			throw err;
		}	
	});
  }
});

You need to use throw new Meteor.Error. Check the docs:

…Meteor.Error is the only kind of error that a server will send to the client…

1 Like

Thanks, I check and saw that I was wrong RPC. Because I was implement all call with asyncronous mode. I change some call. Thanks.

1 Like