I’m trying to insert something into a mongo collection within a Meteor.method and use a callback to handle errors.
I thought I could just throw an error inside the error callback but evidently you can’t do this. Throwing an error here simply prints the error to the server console and continues on as normal. Nothing is sent back to the client calling the method.
What I want to do is tell the client there’s an error and stop.
Is there any way to do this? I don’t really want to use a try/catch block and use a blocking mongo insert and catch the exception instead of using a callback but that’s all I can think of, there must be a non-hacky way of doing something this simple?
Relevant code below:
//server
Meteor.methods({
'uploadWalletImage': function (fileName, imageOf, binaryData, md5) {
WalletImages.insert({_id: md5, 'imageOf': imageOf}, function(error,result){
if(error){throw new Meteor.Error('error', 'reason for error')}; //reported on server console only
});
//other stuff here proceeds as normal even when an error has been thrown
}
});
//client
Meteor.call('uploadWalletImage', file.name, event.target.id, reader.result, md5, function(error, result){
console.log(error.reason); //nothing reported