Can't catch the meteor error thrown into the Method from the event

I have a method and it throws an error, so I can catch it in my case and display it to the user, like this:

  Meteor.methods({
    addPlayer: function(nickname) {
      if (nickname == "") {
        throw new Meteor.Error('empty-nickname', 'You must choose a nickname');
      } else {
        Player.insert({
          nickname: nickname,
        });
      }
    },
  })

      

and in my case

'submit form': function (e) {
  e.preventDefault();

  var nickname = $('input').val();

  Meteor.call('addPlayer', nickname, function(error, result) {
    if (error) {
      console.log(typeof error);
      console.log(error);
    }
  });
}

      

However, the meteorite still throws an exception when simulating the effect of calling 'addPlayer' and the error variable is not an error object, but a string with the same message as the console log, so I get two errors on the console instead of the error object.

The wrap.call method in try / catch doesn't work.

What am I missing here?

- Edit Here is the screen for printing the result: Console print screen

Image link for full resolution: http://i.stack.imgur.com/zABar.png

+3


source to share


1 answer


Throw an error only on the server. Wrap it up insideif(!this.isSimulation) {}



Meteor.methods({
  addPlayer: function(nickname) {
    if (nickname == "") {
      if(!this.isSimulation) {
        throw new Meteor.Error('empty-nickname', 'You must choose a nickname');
      }
    } else {
      Player.insert({
        nickname: nickname,
      });
    }
  },
})

      

+1


source







All Articles