Exception: X::TooManyRequests
- Inherits:
-
ClientError
- Object
- StandardError
- Error
- HTTPError
- ClientError
- X::TooManyRequests
- Defined in:
- lib/x/errors/too_many_requests.rb
Overview
Error raised when rate limit is exceeded (HTTP 429)
Constant Summary
Constants inherited from HTTPError
HTTPError::JSON_CONTENT_TYPE_REGEXP
Instance Attribute Summary
Attributes inherited from HTTPError
Instance Method Summary collapse
-
#rate_limit ⇒ RateLimit?
Get the most restrictive rate limit.
-
#rate_limits ⇒ Array<RateLimit>
Get all rate limits from the response.
-
#reset_at ⇒ Time
Get the time when the rate limit resets.
-
#reset_in ⇒ Integer
(also: #retry_after)
Get the seconds until the rate limit resets.
Methods inherited from HTTPError
#error_message, #initialize, #json?, #message_from_json_response
Constructor Details
This class inherits a constructor from X::HTTPError
Instance Method Details
#rate_limit ⇒ RateLimit?
Get the most restrictive rate limit
14 15 16 |
# File 'lib/x/errors/too_many_requests.rb', line 14 def rate_limit rate_limits.max_by(&:reset_at) end |
#rate_limits ⇒ Array<RateLimit>
Get all rate limits from the response
24 25 26 27 28 |
# File 'lib/x/errors/too_many_requests.rb', line 24 def rate_limits @rate_limits ||= RateLimit::TYPES.filter_map do |type| RateLimit.new(type:, response:) if response["x-#{type}-remaining"].eql?("0") end end |
#reset_at ⇒ Time
Get the time when the rate limit resets
36 37 38 |
# File 'lib/x/errors/too_many_requests.rb', line 36 def reset_at rate_limit&.reset_at || Time.at(0) end |
#reset_in ⇒ Integer Also known as: retry_after
Get the seconds until the rate limit resets
46 47 48 |
# File 'lib/x/errors/too_many_requests.rb', line 46 def reset_in [(reset_at - Time.now).ceil, 0].max end |