Exception: RateLimiter::LimitExceeded

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rate_limiter/limit_exceeded.rb

Overview

A rate limit has been exceeded.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_inObject (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_codeObject (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

#typeObject (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

#descriptionObject



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_leftObject



26
27
28
# File 'lib/rate_limiter/limit_exceeded.rb', line 26

def time_left
  @time_left ||= RateLimiter.time_left(@available_in)
end