Call error in Meteor method from Mongo insert error


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 like this:

//in Template. ... .events"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 if the Task.insert inner function throw an error. And I don’t know why.
Thank you for answers.


Read this, maybe help you: