diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 2e3e48f92..cad92bd01 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -44,14 +44,17 @@ class Rack::Attack self.throttled_responder = lambda do |env| match_data = env["rack.attack.match_data"] - now = match_data[:epoch_time] - headers = { - "RateLimit-Limit" => match_data[:limit].to_s, - "RateLimit-Remaining" => "0", - "RateLimit-Reset" => (now + (match_data[:period] - now % match_data[:period])).to_s, - } - - [429, headers, ["Throttled\n"]] + if match_data + now = match_data[:epoch_time] + headers = { + "RateLimit-Limit" => match_data[:limit].to_s, + "RateLimit-Remaining" => "0", + "RateLimit-Reset" => (now + (match_data[:period] - now % match_data[:period])).to_s, + } + [429, headers, ["Throttled\n"]] + else + [429, {}, ["Throttled but no match data\n"]] + end end end