Call error in Meteor method from Mongo insert error


#1

Hello @ll,

I have a simple question:

I call a method from client. In this method is a Mongo.insert() function with inner function to get the error or result like this:

Task.insert({task: "task01"}, function(err, res) { ... });

Now I want to make a test and try to throw an error from the Task.insert() function like this:

//in Meteor.methods
Task.insert({task: "task01"}, function(err, res) { 
    if (res) {
        throw new Meteor.Error("Something goes wrong");
    }
);

and to get also the error in Meteor.call like this:

//in Template. ... .events
Meteor.call("method", function(err, res) {
    if (err) {
        //do something if the inner function of Task.insert throw an error
    }
);

But I didn’t get the error from the Meteor.call if the Task.insert inner function throw an error. And I don’t know why.
Thank you for answers.


#2

Read this, maybe help you: http://www.smashingthingstogether.com/handling-errors-in-meteor-methods/