Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ensure that status codes are logged properly #2133

Merged
merged 1 commit into from

2 participants

Jesse Storimer José Valim
Jesse Storimer

Had to move AC::Metal::Instrumentation before AC::Metal::Rescue so that status codes set by rescue_from blocks are logged properly.

Previously, the Rails logger was logging a Completed 500 for anything that passed through a rescue_from block, even if it set a different status code for the response.

Jesse Storimer jstorimer Ensure that status codes are logged properly
Needed to move AC::Metal::Instrumentation before AM::Metal::Rescue
so that status codes rendered from rescue_from blocks are logged
properly.
ac81af4
José Valim josevalim merged commit b475f74 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 18, 2011
  1. Jesse Storimer

    Ensure that status codes are logged properly

    jstorimer authored
    Needed to move AC::Metal::Instrumentation before AM::Metal::Rescue
    so that status codes rendered from rescue_from blocks are logged
    properly.
This page is out of date. Refresh to see the latest.
8 actionpack/lib/action_controller/base.rb
View
@@ -212,16 +212,16 @@ def self.without_modules(*modules)
# also include them at the bottom.
AbstractController::Callbacks,
+ # Append rescue at the bottom to wrap as much as possible.
+ Rescue,
+
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
Instrumentation,
# Params wrapper should come before instrumentation so they are
# properly showed in logs
- ParamsWrapper,
-
- # The same with rescue, append it at the end to wrap as much as possible.
- Rescue
+ ParamsWrapper
]
MODULES.each do |mod|
19 actionpack/test/controller/log_subscriber_test.rb
View
@@ -6,6 +6,13 @@ module Another
class LogSubscribersController < ActionController::Base
wrap_parameters :person, :include => :name, :format => :json
+ class SpecialException < Exception
+ end
+
+ rescue_from SpecialException do
+ head :status => 406
+ end
+
def show
render :nothing => true
end
@@ -39,6 +46,10 @@ def with_exception
raise Exception
end
+ def with_rescued_exception
+ raise SpecialException
+ end
+
end
end
@@ -195,6 +206,14 @@ def test_process_action_with_exception_includes_http_status_code
assert_match(/Completed 500/, logs.last)
end
+ def test_process_action_with_rescued_exception_includes_http_status_code
+ get :with_rescued_exception
+ wait
+
+ assert_equal 2, logs.size
+ assert_match(/Completed 406/, logs.last)
+ end
+
def logs
@logs ||= @logger.logged(:info)
end
Something went wrong with that request. Please try again.