lol-js
lol-js copied to clipboard
getting a 429 is not obvious when doing certain api calls
Hello,
So I was doing a bunch of getMatch
(about 1000) and I was wondering why err and body were null for 99% of them. I took the same parameters to the Riot Api explorer and I was getting a 429 (rate limit exceeded). Now the problem is, my code has no way of knowing I got a 429 as the error and body in the callback were both null. I just assumed a null body means something happened with the request and I should just ignore it and move on. Can you add something (either dont call the callback until I can safely call the api again due to the rate limit) or put the error in the error parameter of the callback (so I can just wait x seconds and try again)? Or let me know if I am not understanding something in your api correctly.
just to give a snippet to what I was doing
async.eachLimit(matches, 1, (matchObj, eachCB) => {
RiotApi.getMatch(region, matchObj.match_id, { includeTimeline: true }, (err, body) => {
if (err || !body) {
console.error(`\nfailed to get match data: ${matchObj.match_id}, name: ${matchObj.name}.`, err, `body:`, body)
return eachCB()
}
...
eachCB()
})
})
It sounds like you aren't using the built in rate limiting. lol-js should do the waiting for you if you set it up correctly. For starters, are you giving your client method a rateLimit variable?
nope, everything is pretty default:
var LolApi = require('lol-js')
var request = require('request')
var config = require('./config')
var lolClient = LolApi.client({
apiKey: config.key,
cache: LolApi.redisCache({ host: '127.0.0.1', port: 6379 })
})
module.exports = lolClient
So, for starters, if you pass in the rate limit numbers that Riot assigns you, it's unlikely you'll ever get a 429 since lol-js will rate limit for you. But, even if you do get a 429, lol-js should retry forever until it gets back a result. If you have a sample project that can make this happen, I'm definitely interested.
You should be good if you have a default Riot api key, it looks like lol-js defaults to using that rate limit: [{time: 10, limit: 10}, {time: 600, limit: 500}] I guess you're bypassing the limiting somehow?