Skip to content
Browse files

log 404 status when ActiveRecord::RecordNotFound was raised (#7646)

Conflicts:
	actionpack/CHANGELOG.md
	actionpack/lib/action_controller/log_subscriber.rb
  • Loading branch information...
1 parent ee43989 commit dd76b3bbc8c4b161e6d4f77012c90960f68d1ac3 @senny senny committed with rafaelfranca Sep 16, 2012
View
4 actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 3.2.9 (unreleased) ##
+* Fix #7646, the log now displays the correct status code when an exception is raised.
+
+ *Yves Senn*
+
* Fix handling of date selects when using both disabled and discard options.
Fixes #7431.
View
3 actionpack/lib/action_controller/log_subscriber.rb
@@ -20,7 +20,8 @@ def process_action(event)
status = payload[:status]
if status.nil? && payload[:exception].present?
- status = Rack::Utils.status_code(ActionDispatch::ExceptionWrapper.new({}, payload[:exception]).status_code)
+ exception_class_name = payload[:exception].first
+ status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
end
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in %.0fms" % event.duration
message << " (#{additions.join(" | ")})" unless additions.blank?
View
8 actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
@@ -34,7 +34,7 @@ def rescue_template
end
def status_code
- Rack::Utils.status_code(@@rescue_responses[@exception.class.name])
+ self.class.status_code_for_exception(@exception.class.name)
end
def application_trace
@@ -49,6 +49,10 @@ def full_trace
clean_backtrace(:all)
end
+ def self.status_code_for_exception(class_name)
+ Rack::Utils.status_code(@@rescue_responses[class_name])
+ end
+
private
def original_exception(exception)
@@ -75,4 +79,4 @@ def backtrace_cleaner
@backtrace_cleaner ||= @env['action_dispatch.backtrace_cleaner']
end
end
-end
+end
View
15 actionpack/test/controller/log_subscriber_test.rb
@@ -54,6 +54,10 @@ def with_exception
def with_rescued_exception
raise SpecialException
end
+
+ def with_action_not_found
+ raise AbstractController::ActionNotFound
+ end
end
end
@@ -225,6 +229,17 @@ def test_process_action_with_rescued_exception_includes_http_status_code
assert_match(/Completed 406/, logs.last)
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
@logs ||= @logger.logged(:info)
end

0 comments on commit dd76b3b

Please sign in to comment.
Something went wrong with that request. Please try again.