throwStubExceptions produce uncaught errors


#1

How is throwStubExceptions used? When throwStubExceptions is false the error is logged to console.

Meteor.apply('myMethod', [], {throwStubExceptions:false}, function(error, result) {
  if (error) {
    console.log(error);
  }
})

Meteor.methods({
  myMethod: function() {
    throw new Meteor.Error('bad stuff happened');
  }
})

If throwStubExceptions is changed to true then it makes an uncaught error and error in the callback is undefined. Is this a bug?


#2

We are also seeing this, I’m not sure if this forum is the right place to track it… ?


#3

I’m pretty sure the behaviour in the OP is as documented, especially given the method code used.


#4

Ok, but how can I catch the errors on the client?


#5

I just use try/catch:

try {
  Meteor.apply('abc', parameters, { throwStubExceptions: true }, (err, res) => {
    console.log('method returned', err, res);
  });
} catch (error) {
  console.log('caught error', error);
}

#6

That seems to work, thanks!