How can I fill out err,suc parameters of a callback?

Hello,

I would like to manually fill these values in the callback parameters.

Client*
Meteor.call('something, “http://localhost:3000/search”, function(err, suc){ << those one
if(err){
console.log(err); //Should display >MINE!<
}
if (suc){
console.log(suc);//Should display >YOURS!<
}
});

Server
’'something": function(call_backurl){
return {err: ‘MINE’, suc:‘YOURS’};
}

I hope I can make myself clear, I am just figuring out how I can do this >_<. Thank you.

Hi!

On the server side you return what you want as a Response (err, res) and throw what you want as an Error (err, res).

Response: return ‘Yours’

Error: throw new Error(“MINE”)

"something": function(call_backurl){
 if (1===1) {
   return 'YOURS';
 } else {
   throw new Error("MINE")
 }
}

Let me know if this ain’t clear.

Best regards.

1 Like

Wow, yes it is very clear, thank you! never thought about this :)!!!, I was pulling my hair all day long!.

1 Like

Hey!, I was wondering if I got the same situation but lets say I got this method,

function foo (1,2,callback(bank1,bank2,bank3)){

if (bank1) console.log(‘yes’);

if(bank2) console.log(‘woo’);

if(bank3) console.log(‘weee’);

}

How can I accomplish this to fill the 3 parameters? Your answer is perfect for the Meteor solution, but now I am in need of this? Any ideas? :smiley: