diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-03 23:33:34 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-03 23:33:34 +0100 |
commit | 53c6984944b03b5de036167a418593dfcd12e886 (patch) | |
tree | 6f05fd9951fdee92e4734ec4d2ccb00b4dd76b1e /actionpack/lib/action_dispatch/middleware | |
parent | 6fbe9ef2ffb1858027130789246f3ae24a0a182f (diff) | |
download | rails-53c6984944b03b5de036167a418593dfcd12e886.tar.gz rails-53c6984944b03b5de036167a418593dfcd12e886.tar.bz2 rails-53c6984944b03b5de036167a418593dfcd12e886.zip |
Add notifications to ActionDispatch::ShowExceptions, this can be used as hooks for plugins like ExceptionNotifier.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/show_exceptions.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 4ebc8a2ab9..af356707c6 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -1,7 +1,24 @@ require 'active_support/core_ext/exception' +require 'active_support/notifications' require 'action_dispatch/http/request' module ActionDispatch + # This middleware rescues any exception returned by the application and renders + # nice exception pages if it's being rescued locally. + # + # Every time an exception is caught, a notification is published, becoming a good API + # to deal with exceptions. So, if you want send an e-mail through ActionMailer + # everytime this notification is published, you just need to do the following: + # + # ActiveSupport::Notifications.subscribe "action_dispatch.show_exception" do |name, start, end, instrumentation_id, payload| + # ExceptionNotifier.deliver_exception(start, payload) + # end + # + # The payload is a hash which has to pairs: + # + # * :env - Contains the rack env for the given request; + # * :exception - The exception raised; + # class ShowExceptions LOCALHOST = '127.0.0.1'.freeze @@ -44,8 +61,11 @@ module ActionDispatch def call(env) @app.call(env) rescue Exception => exception - raise exception if env['action_dispatch.show_exceptions'] == false - render_exception(env, exception) + ActiveSupport::Notifications.instrument 'action_dispatch.show_exception', + :env => env, :exception => exception do + raise exception if env['action_dispatch.show_exceptions'] == false + render_exception(env, exception) + end end private |