lib/schneiderlein/fly_catcher.rb in schneiderlein-1.3.1 vs lib/schneiderlein/fly_catcher.rb in schneiderlein-2.0.0
- old
+ new
@@ -1,15 +1,21 @@
# frozen_string_literal: true
module Schneiderlein
class FlyCatcher < Struct.new(:app)
- def call(env)
- begin
- app.call(env)
- rescue ActionDispatch::ParamsParser::ParseError => e
- env['rack.schneiderlein.parse_errors'] ||= []
- env['rack.schneiderlein.parse_errors'] << e
- app.call(remove_errors_from(env))
+
+ PARSE_ERROR_CONSTANT =
+ if Rails.version.to_f < 5.1
+ ActionDispatch::ParamsParser::ParseError
+ else
+ ActionDispatch::Http::Parameters::ParseError
end
+
+ def call(env)
+ app.call(env)
+ rescue PARSE_ERROR_CONSTANT => e
+ env['rack.schneiderlein.parse_errors'] ||= []
+ env['rack.schneiderlein.parse_errors'] << e
+ app.call(remove_errors_from(env))
end
private
def remove_errors_from(env)