mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Move descriptions for rate limiting errors into the exception
This commit is contained in:
@@ -2,10 +2,22 @@ class RateLimiter
|
||||
|
||||
# A rate limit has been exceeded.
|
||||
class LimitExceeded < StandardError
|
||||
attr_accessor :available_in
|
||||
|
||||
def initialize(available_in)
|
||||
@available_in = available_in
|
||||
end
|
||||
|
||||
def description
|
||||
time_left = ""
|
||||
if @available_in < 1.minute.to_i
|
||||
time_left = I18n.t("rate_limiter.seconds", count: @available_in)
|
||||
elsif @available_in < 1.hour.to_i
|
||||
time_left = I18n.t("rate_limiter.minutes", count: (@available_in / 1.minute.to_i))
|
||||
else
|
||||
time_left = I18n.t("rate_limiter.hours", count: (@available_in / 1.hour.to_i))
|
||||
end
|
||||
I18n.t("rate_limiter.too_many_requests", time_left: time_left)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user