Skip to content

How to fail an exceeded rate limit, instead of waiting? #36

Answered by dhempy
dhempy asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it appears this works as expected. Here is what I ended up with:

    %i[flaky_api_get flaky_api_put flaky_api_post].each do |method|
      limit_method(method, rate: 4, interval: 1) do
        Rails.logger.error "Rate limiting Flakey request: #{method}"
        raise FlakyRateLimitSelf, "Rate limiting Flakey request: #{method}"
      end
    end

And out of paranoia, I tested it:

      it do
        Timecop.freeze do
          expect { 10.times { FlakyService.send(method_name) } }
            .to raise_error(Auth0RateLimitSelf, "Rate limiting FlakyService request: #{method_name}")
        end
      end
 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dhempy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant