how to return error from Meteor.methods function? I call my function:
Meteor.call('checkCode', mycode, function(error,result){
console.log(result['name']);
})
And it returns me name of person whose "code" is the same as argument. But how return an error if there is nobody with input code? My function code:
checkCode: function(zcode){
return Codes.findOne({code: zcode});
}
Thanks!:)
You can use throw
as you would any normal javascript error. Meteor picks it up and returns the error to the client.
var code = Codes.findOne({code: zcode});
if(!code)
throw new Meteor.Error(500, 'Error 500: Not found', 'the document is not found');
return code;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With