In my meteor project, I want to use generic functions in my Meteor.methods (Mostly because I don’t want users to call this functions from the client).
I’m defining this function in another file :
const ldapPing = (callback) => {
try {
ldapAuth.client = createClient({
url: Meteor.settings.private.LDAP.URL,
});
ldapAuth.client.on('error', () => {
throw new Meteor.Error('500', 'Cant join.');
});
callback(null, true);
} catch (exception) {
callback(exception, null);
}
};
And I’m calling it in my meteor methods like this :
'test.ldap': function testLdap() {
try {
const future = new Future();
ldapPing((error, result) => {
console.log('ERROR : ' + error);
console.log('RESULT : ' + result);
if (error) {
future.throw(error);
} else {
future.return(true);
}
});
return future.wait();
} catch (exception) {
throw exception;
}
},
However, the Meteor.error is not returned to the Meteor method and is immediatly throw from the simple function ldapPing, which stops meteor with “Exited with code: 1”.
Any idea why ?
(This example is made for this question, ofc in this case there is no benefits to externalize this function)