Rate limiting - how to handle it?
Closed this issue · 6 comments
Hi,
I used rate limiting with documentation, but I has error (429).
How to handle it? I used newest version of script and PHP 7.2.
This rate limiting works?
Hello, well it is supposed to work! 😄 Any further information you could provide (exact error message, which endpoints you are using, which regions, ...)?
Uncaught RiotAPI\LeagueAPI\Exceptions\ServerLimitException: API call rate limit would be exceeded by this call. in /home/dosuch/websites/lol/wp-content/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php:627
Endpoints: mainly match/summoner
Region: EUW
I have too errors like that:
- Uncaught RiotAPI\LeagueAPI\Exceptions\ServerException: LeagueAPI: Unspecified error occured (504). Gateway timeout in /home/dosuch/websites/lol/wp-content/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php:1272
- Uncaught RiotAPI\LeagueAPI\Exceptions\ForbiddenException: LeagueAPI: Forbidden. Forbidden in /home/dosuch/websites/lol/wp-content/vendor/dolejska-daniel/riot-api/src/LeagueAPI/LeagueAPI.php:1265
The server limit exception you have shown is intentional and actually prevents the call that would cause exceeding the limit - https://github.com/dolejska-daniel/riot-api/blob/master/src/LeagueAPI/LeagueAPI.php#L624-L628.
The "Gateway timeout" exception depends on service health - probably some internal things at Riot.
The "Forbidden" exception probably means that you do not have access to used resource/endpoint (like Tournament APIs etc.) or your authorization failed (invalid API token).
How to handle this error in your library? Did you have tips?
As I've said - the error is intentional, so you just need try-catch
block around the calls that could cause it (which are all except StaticData
endpoints). You can either wait in the script after reaching ServerLimitException
or do something else, that's up to you.
try {
// api call
} catch (ServerLimitException $ex) {
// sort this out
}
// continue
Thanks for help. I try it!