Loren
Loren

Reputation: 14896

How do I view thrown errors in Meteor methods?

I'd like to see instances of Meteor.Error as well as anything else that is thrown. On the server side, I'm looking at what is printed out to the console after running the meteor command (in development on localhost:3000). On the client, I'm looking at the JS console.

When a Meteor.Error is thrown on the client, I see it on the client console. When a Meteor.Error is thrown on the server, I see nothing on either side. When other types of errors are thrown on either side (for example, assert(false) with the mrt assert package), I see it on neither side.

Upvotes: 3

Views: 979

Answers (1)

Tarang
Tarang

Reputation: 75975

It depends where you throw the Meteor.Error, it needs a context to give to the client.

If you throw a Meteor.Error in a method you will see it come back in the err of the callback of the client side call. e.g

Server side

Meteor.methods({
    'crashme':function() {
        throw new Meteor.Error(500, "Error Title", "details", "more details");
    }
});

Client side

Meteor.call("crashme", function(err, result) {
    console.log(err);
    //--> Prints the thrown error
});

Upvotes: 5

Related Questions