From 6351de159c85993cf6461a7e4ec25dd7a616c995 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 7 Mar 2022 09:36:33 +0000 Subject: [PATCH] Redirect to the too many requests error page --- config/initializers/rack_attack.rb | 7 +++++++ config/routes.rb | 2 +- spec/requests/rack_attack_spec.rb | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index a9bc15f45..f5f86b742 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -11,3 +11,10 @@ Rack::Attack.throttle("password reset requests", limit: 5, period: 60.seconds) d request.params["user"]["email"].to_s.downcase.gsub(/\s+/, "") end end + +Rack::Attack.throttled_responder = lambda do |_env| + headers = { + "Location" => "/429", + } + [301, headers, []] +end diff --git a/config/routes.rb b/config/routes.rb index 730145ee8..c230a969c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,7 @@ Rails.application.routes.draw do scope via: :all do match "/404", to: "errors#not_found" - match "/429", to: "errors#too_many_requests" + match "/429", to: "errors#too_many_requests", status: 429 match "/422", to: "errors#unprocessable_entity" match "/500", to: "errors#internal_server_error" end diff --git a/spec/requests/rack_attack_spec.rb b/spec/requests/rack_attack_spec.rb index 3fd5cc850..a265261ab 100644 --- a/spec/requests/rack_attack_spec.rb +++ b/spec/requests/rack_attack_spec.rb @@ -54,6 +54,7 @@ describe "Rack::Attack" do it "throttles" do over_limit.times do post "/users/password", params: params + follow_redirect! end last_response = response expect(last_response.status).to eq(429)