node-strava / node-strava-v3

API wrapper for Strava's v3 API, in Node
MIT License
356 stars 109 forks source link

Cannot read property 'headers' of undefined #64

Closed vlavrynovych closed 5 years ago

vlavrynovych commented 7 years ago

/Users/vlavrynovych/Workspace/vlavrynovych/strive/node_modules/strava-v3/lib/util.js in Request._callback at line 220:52

request(options, function (err, response, payload) {
        if (err) {
            console.log('api call error');
            console.log(err);
        }

        done(err, payload, parseRateLimits(response.headers)); // <----- this line
    });
};

function parseRateLimits(headers) {
    if(!headers[util.rateLimit] || !headers[util.rateUsage]) {
        return null;
    }
vlavrynovych commented 7 years ago

Please assign to me. I'll do the PR

markstos commented 7 years ago

@vlavrynovych this issue is also addressed using a different approach in my promise-based fork that I have open PRs to merge. What I did was to follow the design that Strava uses in their own Go-based REST client. Instead of including an extra payload argument to the callback`, the module stores the rate-limiting status globally. A couple convenient methods are added to check the status:

https://github.com/RideAmigosCorp/node-strava-v3/tree/ra-fixes#global-status

// returns true if the most recent request exceeded the rate limit
strava.rateLimiting.exceeded()

// returns the current decimal fraction (from 0 to 1) of rate used. The greater of the short and long term limits.
strava.rateLimiting.fractionReached();
vlavrynovych commented 7 years ago

@markstos original problem isn't related to the rate limiting. I'm getting exception in my project once I reach limit. As for me there is no difference how to get rate limiting info. I just want to stabilize the execution process.

markstos commented 5 years ago

The promise-based fork is getting merged. Since I think the issue is resolved there, I'm closing this.