Skip to content

Instantly share code, notes, and snippets.

@kedarmhaswade
Created November 5, 2012 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kedarmhaswade/4019271 to your computer and use it in GitHub Desktop.
Save kedarmhaswade/4019271 to your computer and use it in GitHub Desktop.
Ensuring proper order of rack middlewares
MyApp::Application.config.middleware.insert_before ActionDispatch::ShowExceptions, ExceptionNotifier,
:sender_address => "sender@gmail.com",
:exception_recipients => "receiever@gmail.com",
MyApp::Application.config.middleware.insert_after ExceptionNotifier, ActionDispatch::ShowExceptions
require 'action_dispatch/middleware/show_exceptions'
module ActionDispatch
class ShowExceptions
private
def render_exception_with_template(env, exception)
env[:exception] = exception
body = ErrorsController.action(rescue_responses[exception.class.name]).call(env)
log_error(exception)
MailNotifications.fix_asap(clean_backtrace(exception, :all)).deliver if Rails.env.production? # hope this does not throw any exceptions
body
rescue
render_exception_without_template(env, exception)
end
alias_method_chain :render_exception, :template
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment