Skip to content
Browse files

added new middleware catcher, fixes #73

  • Loading branch information...
1 parent 73de36b commit e13041bf9c69527b9bb34043617e52b6c7615657 @shime shime committed Apr 9, 2012
View
18 lib/airbrake/rails/controller_methods.rb
@@ -1,6 +1,16 @@
module Airbrake
module Rails
module ControllerMethods
+
+ def airbrake_request_data
+ { :parameters => airbrake_filter_if_filtering(params.to_hash),
+ :session_data => airbrake_filter_if_filtering(airbrake_session_data),
+ :controller => params[:controller],
+ :action => params[:action],
+ :url => airbrake_request_url,
+ :cgi_data => airbrake_filter_if_filtering(request.env) }
+ end
+
private
# This method should be used for sending manual notifications while you are still
@@ -25,14 +35,6 @@ def airbrake_ignore_user_agent? #:nodoc:
Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
end
- def airbrake_request_data
- { :parameters => airbrake_filter_if_filtering(params.to_hash),
- :session_data => airbrake_filter_if_filtering(airbrake_session_data),
- :controller => params[:controller],
- :action => params[:action],
- :url => airbrake_request_url,
- :cgi_data => airbrake_filter_if_filtering(request.env) }
- end
def airbrake_filter_if_filtering(hash)
return hash if ! hash.is_a?(Hash)
View
31 lib/airbrake/rails/middleware/debug_exceptions_catcher.rb
@@ -0,0 +1,31 @@
+module Airbrake
+ module Rails
+ module Middleware
+ module DebugExceptionsCatcher
+ def self.included(base)
+ base.send(:alias_method_chain,:render_exception,:airbrake)
+ end
+
+ def define_proxy_class(klass)
+ klass.class_eval do
+ def call_the_real_method_if_exists
+ rescue_action_in_public_without_airbrake(request.env['fake_exception'])
+ end
+ end
+ end
+
+ def render_exception_with_airbrake(env,exception)
+ controller = env['action_controller.instance']
+ env['airbrake.error_id'] = Airbrake.notify_or_ignore(exception, controller.airbrake_request_data)
+ if defined?(controller.rescue_action_in_public_without_airbrake)
+ env['fake_exception'] = exception
+ define_proxy_class(controller.class)
+ controller.class.action(:call_the_real_method_if_exists).call(env)
+ else
+ render_exception_without_airbrake(env,exception)
+ end
+ end
+ end
+ end
+ end
+end
View
7 lib/airbrake/railtie.rb
@@ -9,7 +9,7 @@ class Railtie < ::Rails::Railtie
end
initializer "airbrake.use_rack_middleware" do |app|
- app.config.middleware.use "Airbrake::Rack"
+ app.config.middleware.use "Airbrake::Rack" unless defined?(::ActionDispatch::DebugExceptions)
app.config.middleware.insert 0, "Airbrake::UserInformer"
end
@@ -27,6 +27,11 @@ class Railtie < ::Rails::Railtie
::ActionController::Base.send(:include, Airbrake::Rails::ControllerMethods)
::ActionController::Base.send(:include, Airbrake::Rails::JavascriptNotifier)
+
+ if defined?(::ActionDispatch::DebugExceptions)
+ require 'airbrake/rails/middleware/debug_exceptions_catcher'
+ ::ActionDispatch::DebugExceptions.send(:include,Airbrake::Rails::Middleware::DebugExceptionsCatcher)
+ end
end
end
end

0 comments on commit e13041b

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