Skip to content
Permalink
Browse files

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")
  • Loading branch information
SamSaffron committed Feb 14, 2018
1 parent 0b13b82 commit 38f4acd55a3d9c3c8cf03d5071139975079b9a56
@@ -107,7 +107,7 @@ class RenderEmpty < StandardError; end
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
@@ -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."
@@ -26,6 +26,7 @@
end

it 'can cleanly limit requests' do
freeze_time
#request.set_header("action_dispatch.show_exceptions", true)

admin = Fabricate(:admin)
@@ -46,5 +47,9 @@
}

expect(response.status).to eq(429)

data = JSON.parse(response.body)

expect(data["extras"]["wait_seconds"]).to eq(60)
end
end

1 comment on commit 38f4acd

@discoursebot

This comment has been minimized.

Copy link

discoursebot commented on 38f4acd Feb 14, 2018

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/global-rate-limits-and-throttling-in-discourse/78612/5

Please sign in to comment.
You can’t perform that action at this time.