Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Response Header with X-Rate-Limit-Count #119

Open
alabama opened this issue Aug 27, 2016 · 7 comments
Open

[Proposal] Response Header with X-Rate-Limit-Count #119

alabama opened this issue Aug 27, 2016 · 7 comments

Comments

@alabama
Copy link
Contributor

alabama commented Aug 27, 2016

Hey,

what do you guys think to add header information to the client response class? With that information you can improve the limit process. The API returns header information described here: https://developer.riotgames.com/docs/rate-limiting

The real problem i run into was this: https://developer.riotgames.com/discussion/community-discussion/show/VeazJAgi
RiotSchmick (NA) describes, that you can get a 429 but without the "Retry-After" header information, which means that the league of legends service itself had a problem serving the requested data. For me this issue occurred very often in the matchlist and specific match request.

So what do you think about adding header information into the Response class and handling this "429 Response Error" different?

@phelion
Copy link

phelion commented Sep 1, 2016

I favor this idea, have the same problem here 😉

@dnlbauer
Copy link
Collaborator

i'd like to have that too, but im dont have enough time to do that right now :/
If you want to make this, pull requests are welcome as always :)

@m1so
Copy link
Contributor

m1so commented Oct 17, 2016

handling this "429 Response Error" different?

What do you have in mind @alabama @danijoo? Some endpoint won't return X-Rate-Limit-Type or Retry-After header as mentioned in Rate limiting docs, which means that when you hit that endpoint's rate limit there is no way to determine how much time you should wait for the next request.

One option is to add a condition and new exception when checking for request errors in AbstractApi

if ($response->getCode() === 429 && !$response->hasHeader('Retry-After')) {
    throw new UnderlyingServiceRateLimitReached('...');
}

class UnderlyingServiceRateLimitReached extends HttpServerError {} 

but that would require adding header information to Client and ClientInterface classes.

Then you should be able to handle this special case in your code by for example creating auto-retry method

class RequestUtils
{
    public static function autoRetry(callable $f)
    {
        try { 
            $f();
        } catch (UnderlyingServiceRateLimitReached $e) { 
            sleep(2);
            static::autoRetry($f);
        } catch (...) { ... }
    }
}

@dnlbauer
Copy link
Collaborator

dnlbauer commented Oct 19, 2016

I merged your pull request. Maybe you can even extend this so UnderlyingServiceRateLimitReached includes a field holding header value of Retry-After:

public static function autoRetry(callable $f)
    {
        try { 
            $f();
        } catch (UnderlyingServiceRateLimitReached $e) { 
            sleep($e->getRetryAfter());
            static::autoRetry($f);
        } catch (...) { ... }
    }

@m1so
Copy link
Contributor

m1so commented Oct 20, 2016

You mean Http429? Because UnderlyingServiceRateLimitReached is thrown only when Retry-After header is not present in the response.

@dnlbauer
Copy link
Collaborator

yes :)

@dnlbauer
Copy link
Collaborator

yes :)

Michal Baumgartner [email protected] schrieb am Do., 20. Okt. 2016
um 21:08 Uhr:

You mean Http429? Because UnderlyingServiceRateLimitReached is thrown
only when Retry-After header is not present in the response.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#119 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEeQ8tSJi1jLBZ8U5nxWvO6ijQnNGZ6Zks5q17wtgaJpZM4Jus1g
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants