I want to be able return variables, objects and arrays into variables from my Meteor HTTP GET calls or from any other asynchronous function
Referring to MeteorChef tutorial ( https://themeteorchef.com/snippets/synchronous-methods/ ) it can be done by using wrapAsync for HTTP
// Moving from:
HTTP.call('GET', url, header, function( error, response ) {if (error) {console.log(error);} else {console.log}});
// To:
var convertAsyncToSync = Meteor.wrapAsync( HTTP.get ),
resultOfAsyncToSync = convertAsyncToSync(url, header);
Console.log(resultOfAsyncToSync);
However when using the wrapAsync and API brings back data such as Error: failed [404] {"message":"Not Found"}
my app dies. App dies also with HTTP.call('GET', url, header);
when error code is received.
Only way that I can bypass this is to use HTTP.call('GET', url, header, function( error, response ) {if (error) {console.log(error);} else {console.log}});
, but using this I cannot return response into a variable.
What can I do to pass this error? How I can avoid API response codes killing my app? How I can work with API error codes?