Exception: RateLimiter::LimitExceeded
- Inherits:
-
StandardError
- Object
- StandardError
- RateLimiter::LimitExceeded
- Defined in:
- lib/rate_limiter/limit_exceeded.rb
Overview
A rate limit has been exceeded.
Instance Attribute Summary collapse
-
#available_in ⇒ Object
readonly
Returns the value of attribute available_in.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(available_in, type = nil, error_code = nil) ⇒ LimitExceeded
constructor
A new instance of LimitExceeded.
- #time_left ⇒ Object
Constructor Details
#initialize(available_in, type = nil, error_code = nil) ⇒ LimitExceeded
Returns a new instance of LimitExceeded.
20 21 22 23 24 |
# File 'lib/rate_limiter/limit_exceeded.rb', line 20 def initialize(available_in, type = nil, error_code = nil) @available_in = available_in @type = type @error_code = error_code end |
Instance Attribute Details
#available_in ⇒ Object (readonly)
Returns the value of attribute available_in.
18 19 20 |
# File 'lib/rate_limiter/limit_exceeded.rb', line 18 def available_in @available_in end |
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
18 19 20 |
# File 'lib/rate_limiter/limit_exceeded.rb', line 18 def error_code @error_code end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/rate_limiter/limit_exceeded.rb', line 18 def type @type end |
Instance Method Details
#description ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/rate_limiter/limit_exceeded.rb', line 30 def description if @type.present? type_key = @type.tr("-", "_") msg = I18n.t("rate_limiter.by_type.#{type_key}", time_left: time_left, default: "") return msg if msg.present? end I18n.t("rate_limiter.too_many_requests", time_left: time_left) end |
#time_left ⇒ Object
26 27 28 |
# File 'lib/rate_limiter/limit_exceeded.rb', line 26 def time_left @time_left ||= RateLimiter.time_left(@available_in) end |