Should I wrap the Meteor method in a try/catch -- then inside the catch throw a Meteor.Error? Then on the Meteor call, instead of waiting for the callback to log the error, should I wrap the call in a try/catch and log in the catch?
rough example:
/client/meteor_call.js
try {
Meteor.call('do_something', message); <- async call, will catch get called?
} catch (e) {
console.log(e);
}
/lib/meteor_methods.js
do_something: function (message) {
var return_id = '';
try {
return_id = collection_name.insert(message);
} catch (e) {
throw new Meteor.Error(500, 'exception in do_something', e);
} finally {
return return_id;
}
}
Above, the Meteor.Error thrown in the Meteor method would bubble up to the Meteor call on the client, and since the client is not handling the error in the callback, won't the catch on the client catch the it?
If I need to do something with in the callback of the Meteor call, then I can do this I guess:
/client/meteor_call.js
try {
Meteor.call('do_something', message, function (err, return_value) {
// do stuff with return_value
}
} catch (e) {
console.log(e);
}
But should I place another try/catch within the callback, or just leave it out and catch in the outer try/catch?