I’m retrieving a key from an API with a function on the server side. I want to call this function in a function and let it return the key. The problem is that it returns undefined.
With just the first function, the key is succesfully returned. The problem is when I want that function to return the value. I’m running this in my server folder.
The reason it returns undefined is due to the context in which you’re calling it. So moving the logic into a normal function outside that context will work better. Also wrapping it into a promise so you can deal with the async callback.
Hi, thank you for the suggestions. I’m not familiar with this yet though and I can’t seem to figure out how to run the ‘createTournament’ method now? I used Meteor.call before but now it says “Error invoking Method ‘createTournament’: [[object Object]]”.
Edit: all good, apparentely it was a variable that didn’t exist.
@Dan Thank you for the suggestion, definitely seems interesting and I will try your solution when I find the time.
I think you can ditch the promise there and just make it an async function so it returns a promise automatically. async functions should wrap your function in a Promise, convert returns to resolve()s, and convert throws to reject()s