ratelimitj icon indicating copy to clipboard operation
ratelimitj copied to clipboard

Return which limit rule was reached

Open ofirnk opened this issue 6 years ago • 3 comments

We love your published library and very likely to use it.

One idea to improve is to return not just a simple boolean but a rich object of type {isOverLimit:boolean, limitingRule:RequestLimitRule} or similar. Exact type is not critical, it's just the idea of letting the user (be it internal or external) - which limit was reached.

So currently - the user would just get false when she's limited. After - she'd know what exactly blocked her access.

WDYT?

p.s I know it's a major refactor to internal logic + interface.. but it can be done in a non-breaking mode

ofirnk avatar Jul 30 '17 12:07 ofirnk

Yes it is a good idea and something I am considering as it maybe useful to return counts to upstream clients like so:

Status: 200 OK X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4999 X-RateLimit-Reset: 1372700873

This is something that Github's API has https://developer.github.com/v3/rate_limit/

mokies avatar Jul 31 '17 10:07 mokies

Exactly what I was targeting!

ofirnk avatar Jul 31 '17 10:07 ofirnk

Craig, we are making extensive usage of your library to control/limit some protocols. Works like a charm so far (combined with Redis). Returning which limit rule was reached is definitively an important tuning feature. Many thanks for your great job.

coi18n avatar Nov 19 '20 10:11 coi18n