提交 8f0d332a 编写于 作者: R Rafael Mendonça França

Merge pull request #7660 from senny/7646_wrong_status_code_on_not_found

log 404 status when ActiveRecord::RecordNotFound was raised (#7646)
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* Fix #7646, the log now displays the correct status code when an exception is raised.
*Yves Senn*
* Allow pass couple extensions to ActionView::Template.register_template_handler call. *Tima Maslyuchenko* * Allow pass couple extensions to ActionView::Template.register_template_handler call. *Tima Maslyuchenko*
* Sprockets integration has been extracted from Action Pack and the `sprockets-rails` * Sprockets integration has been extracted from Action Pack and the `sprockets-rails`
gem should be added to Gemfile (under the assets group) in order to use Rails asset gem should be added to Gemfile (under the assets group) in order to use Rails asset
pipeline in future versions of Rails. pipeline in future versions of Rails.
*Guillermo Iguaran* *Guillermo Iguaran*
* `ActionDispatch::Session::MemCacheStore` now uses `dalli` instead of the deprecated * `ActionDispatch::Session::MemCacheStore` now uses `dalli` instead of the deprecated
`memcache-client` gem. As side effect the autoloading of unloaded classes objects `memcache-client` gem. As side effect the autoloading of unloaded classes objects
saved as values in session isn't supported anymore when mem_cache session store is saved as values in session isn't supported anymore when mem_cache session store is
used, this can have an impact in apps only when config.cache_classes is false. used, this can have an impact in apps only when config.cache_classes is false.
*Arun Agrawal + Guillermo Iguaran* *Arun Agrawal + Guillermo Iguaran*
......
...@@ -19,7 +19,8 @@ def process_action(event) ...@@ -19,7 +19,8 @@ def process_action(event)
status = payload[:status] status = payload[:status]
if status.nil? && payload[:exception].present? if status.nil? && payload[:exception].present?
status = ActionDispatch::ExceptionWrapper.new({}, payload[:exception]).status_code exception_class_name = payload[:exception].first
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
end end
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.0fms" % event.duration message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.0fms" % event.duration
message << " (#{additions.join(" | ")})" unless additions.blank? message << " (#{additions.join(" | ")})" unless additions.blank?
......
...@@ -37,7 +37,7 @@ def rescue_template ...@@ -37,7 +37,7 @@ def rescue_template
end end
def status_code def status_code
Rack::Utils.status_code(@@rescue_responses[@exception.class.name]) self.class.status_code_for_exception(@exception.class.name)
end end
def application_trace def application_trace
...@@ -52,6 +52,10 @@ def full_trace ...@@ -52,6 +52,10 @@ def full_trace
clean_backtrace(:all) clean_backtrace(:all)
end end
def self.status_code_for_exception(class_name)
Rack::Utils.status_code(@@rescue_responses[class_name])
end
private private
def original_exception(exception) def original_exception(exception)
......
...@@ -54,6 +54,10 @@ def with_exception ...@@ -54,6 +54,10 @@ def with_exception
def with_rescued_exception def with_rescued_exception
raise SpecialException raise SpecialException
end end
def with_action_not_found
raise AbstractController::ActionNotFound
end
end end
end end
...@@ -225,6 +229,17 @@ def test_process_action_with_rescued_exception_includes_http_status_code ...@@ -225,6 +229,17 @@ def test_process_action_with_rescued_exception_includes_http_status_code
assert_match(/Completed 406/, logs.last) assert_match(/Completed 406/, logs.last)
end end
def test_process_action_with_with_action_not_found_logs_404
begin
get :with_action_not_found
wait
rescue AbstractController::ActionNotFound
end
assert_equal 2, logs.size
assert_match(/Completed 404/, logs.last)
end
def logs def logs
@logs ||= @logger.logged(:info) @logs ||= @logger.logged(:info)
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册