FIX: rate limiter text is confusing, should not say daily

Also, adds easily parseable JSON so users can figure out
how long to wait when the API is limited. ("extras" "wait_seconds")
This commit is contained in:
Sam 2018-02-14 15:29:50 +11:00
parent 0b13b82e94
commit 38f4acd55a
3 changed files with 7 additions and 2 deletions

View File

@ -107,7 +107,7 @@ class ApplicationController < ActionController::Base
end
def render_rate_limit_error(e)
render_json_error e.description, type: :rate_limit, status: 429
render_json_error e.description, type: :rate_limit, status: 429, extras: { wait_seconds: e&.available_in }
end
# If they hit the rate limiter

View File

@ -538,7 +538,7 @@ en:
rate_limiter:
slow_down: "You have performed this action too many times, try again later."
too_many_requests: "We have a daily limit on how many times that action can be taken. Please wait %{time_left} before trying again."
too_many_requests: "You have performed this action too many times. Please wait %{time_left} before trying again."
by_type:
first_day_replies_per_day: "You've reached the maximum number of replies a new user can create on their first day. Please wait %{time_left} before trying again."
first_day_topics_per_day: "You've reached the maximum number of topics a new user can create on their first day. Please wait %{time_left} before trying again."

View File

@ -26,6 +26,7 @@ describe 'rate limiter integration' do
end
it 'can cleanly limit requests' do
freeze_time
#request.set_header("action_dispatch.show_exceptions", true)
admin = Fabricate(:admin)
@ -46,5 +47,9 @@ describe 'rate limiter integration' do
}
expect(response.status).to eq(429)
data = JSON.parse(response.body)
expect(data["extras"]["wait_seconds"]).to eq(60)
end
end