Wrong Rate limits
cedricdelpoux opened this issue · 6 comments
Hello, I try to found the best way to handle rate limits but I have some strange behaviors
const handleError = (err) => {
const {
shortTermUsage,
shortTermLimit,
} = strava.rateLimiting
console.lg(shortTermUsage, shortTermLimit)
throw new Error(err.message)
}
const payload = await strava.athlete.listActivities(args).catch(errors.StatusCodeError, handleError)
The error is:
429 - {"message":"Rate Limit Exceeded","errors":[{"resource":"Application","field":"rate limit","code":"exceeded"}]}
But shortTermUsage
is 574 while shortTermLimit is 600
So my script stop. The next time I start my script and I go to handleError
, shortTermUsage
and shortTermLimit
are equal to 0
like not initialized.
Did I miss something?
You are using the Promise API but checking the rate limiting stats collected and reported by the callback API.
The docs provide an alternative rate-limiting API for use with the promise interface.
https://github.com/UnbounDev/node-strava-v3#global-status
If you want to know the detailed difference between how the two alternatives work, read the code.
In the documentation
In our promise API, to track rate limiting we use a global counter accessible through `strava.rateLimiting`. The rate limiting status is updated with each request.
I don't understand what you means because I use the global counter accessible via strava.rateLimiting
. It's what I understand from the documentation
@cedricdelpoux You are welcome to review the rate limiting code to see if there's a bug there:
https://github.com/UnbounDev/node-strava-v3/blob/master/lib/rateLimiting.js
I use strava.rateLimiting.exceeded()
and it seems to be working well for me.
The object strava.rateLimiting
is correct most of the time except when the first fetch thow an error, for example if rate limit exceeded before the first fetch.
I did not try but I think we need to call rateLimiting.updateRateLimits
in a catch
or a finally
here
I just did