2

I've been testing on http calls with meteor, I used nitrous (because I had no access to my dev laptop during the weekend) and it worked fine. But when I tried to run from my local pc it returns:

Exception in delivering result of invoking 'getMatch': TypeError: Cannot read property 'duration' of undefined.

Any ideas of what could be the cause? Method definition:

Dota = {};

Dota.getMatch = function() {
    if (!Meteor.settings.steamToken)
    throw new Meteor.Error(500, 'Enter a valid Steam Token in Meteor.settings');

    var matchResponse = Meteor.http.get(
       "https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?",
        {
            params:{
                "match_id": "1305454585",
                "key": Meteor.settings.steamToken
            }
        }
    );

    if (matchResponse.statusCode === 200) {
        return matchResponse.data.result
    }
    else {
        throw new Meteor.Error(500, "getMatch failed with error: "+matchResponse.statusCode);
    }
}

Meteor.methods({
    'getMatch': function(){
        return Dota.getMatch();
    }
})

Calling the method:

Meteor.call('getMatch', function(error, result){
    var duration = numeral(result.duration).format('00:00:00');
    Session.set('duration', duration);

    var winner = Meteor.myFunctions.getWinner(result.radiant_win);
    Session.set('winner', winner);
});

Template.layout.helpers({
    winner: function () {
        return Session.get('winner');
    },
    duration: function () {
        return Session.get('duration');
    }
});
akrz
  • 458
  • 5
  • 8
  • The only place where you access a property called `duration` is `result.duration` in the method callback. So `result` must be undefined, i.e. the method returns undefined. What do you get if you add `console.log(JSON.stringify(matchResponse.data))` to your method? – user3374348 Mar 09 '15 at 14:32
  • It seems like the method never gets called (the console.log didn't show up). I declared that method from a package, maybe is that the issue? the weird thing is that it's working fine on nitrous – akrz Mar 09 '15 at 23:27
  • Did you check the server logs as well as the client logs? – user3374348 Mar 10 '15 at 06:43

1 Answers1

1

Found a solution, I changed the location of

Meteor.methods({
    'getMatch': function(){
        return Dota.getMatch();
    }
})

to server/server.js (I had it in packages/dota/dota.js) and now it works! Thanks @user3374348 for helping!

akrz
  • 458
  • 5
  • 8