1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't log backtrace for ActionDispatch::Http::MimeNegotiation::InvalidType

This commit is contained in:
Rafael Mendonça França 2020-10-07 17:30:07 +00:00
parent 1e5e1f17d6
commit f2caed1e73
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
2 changed files with 38 additions and 15 deletions

View file

@ -6,21 +6,21 @@ require "rack/utils"
module ActionDispatch
class ExceptionWrapper
cattr_accessor :rescue_responses, default: Hash.new(:internal_server_error).merge!(
"ActionController::RoutingError" => :not_found,
"AbstractController::ActionNotFound" => :not_found,
"ActionController::MethodNotAllowed" => :method_not_allowed,
"ActionController::UnknownHttpMethod" => :method_not_allowed,
"ActionController::NotImplemented" => :not_implemented,
"ActionController::UnknownFormat" => :not_acceptable,
"ActionController::RoutingError" => :not_found,
"AbstractController::ActionNotFound" => :not_found,
"ActionController::MethodNotAllowed" => :method_not_allowed,
"ActionController::UnknownHttpMethod" => :method_not_allowed,
"ActionController::NotImplemented" => :not_implemented,
"ActionController::UnknownFormat" => :not_acceptable,
"ActionDispatch::Http::MimeNegotiation::InvalidType" => :not_acceptable,
"ActionController::MissingExactTemplate" => :not_acceptable,
"ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
"ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
"ActionDispatch::Http::Parameters::ParseError" => :bad_request,
"ActionController::BadRequest" => :bad_request,
"ActionController::ParameterMissing" => :bad_request,
"Rack::QueryParser::ParameterTypeError" => :bad_request,
"Rack::QueryParser::InvalidParameterError" => :bad_request
"ActionController::MissingExactTemplate" => :not_acceptable,
"ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
"ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
"ActionDispatch::Http::Parameters::ParseError" => :bad_request,
"ActionController::BadRequest" => :bad_request,
"ActionController::ParameterMissing" => :bad_request,
"Rack::QueryParser::ParameterTypeError" => :bad_request,
"Rack::QueryParser::InvalidParameterError" => :bad_request
)
cattr_accessor :rescue_templates, default: Hash.new("diagnostics").merge!(
@ -37,7 +37,8 @@ module ActionDispatch
]
cattr_accessor :silent_exceptions, default: [
"ActionController::RoutingError"
"ActionController::RoutingError",
"ActionDispatch::Http::MimeNegotiation::InvalidType"
]
attr_reader :backtrace_cleaner, :exception, :wrapped_causes, :line_number, :file

View file

@ -556,6 +556,28 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest
assert_equal 3, log.lines.count
end
test "doesn't log the framework backtrace when error type is a invalid mine type" do
@app = ProductionApp
output = StringIO.new
backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
backtrace_cleaner.add_silencer { true }
env = { "Accept" => "text/html,*",
"action_dispatch.show_exceptions" => true,
"action_dispatch.logger" => Logger.new(output),
"action_dispatch.backtrace_cleaner" => backtrace_cleaner }
assert_raises ActionDispatch::Http::MimeNegotiation::InvalidType do
get "/invalid_mimetype", headers: env
end
log = output.rewind && output.read
assert_includes log, "ActionDispatch::Http::MimeNegotiation::InvalidType (ActionDispatch::Http::MimeNegotiation::InvalidType)"
assert_equal 3, log.lines.count
end
test "display backtrace when error type is SyntaxError" do
@app = DevelopmentApp