Skip to content

Conversation

@andreimaxim
Copy link

ExceptionNotifier works OK as long as you don't have to manually
call the Notifier#exception_notification method yourself and
rely on the middleware to do your job.

However, if you are using a Rails action to show 500 errors (e.g.
you are using the rescue_from helper in your
ApplicationController), then you will have to reconfigure the
ExceptionNotifier options.

This means that in your controller you'd have something like:

rescue_from Exception, :with => :server_error

def server_error(exception)
  request.env['exception_notifier.options'] = {
    :sender_address => "notifier@example.com",
    :exception_recipients => "dev@example.com"
  }

  ExceptionNotifier::Notifier.exception_notification(
    request.env, exception
  ).deliver
end

... which means code duplication, especially if you have more
than one action that's handling exceptions.

This commit should solve this problem by making the default
attributes writable and use the initial middleware configuration
to set those defaults to something more sensible.

ExceptionNotifier works OK as long as you don't have to manually
call the `Notifier#exception_notification` method yourself and
rely on the middleware to do your job.

However, if you are using a Rails action to show 500 errors (e.g.
you are using the `rescue_from` helper in your
ApplicationController), then you will have to reconfigure the
ExceptionNotifier options.

This means that in your controller you'd have something like:

    rescue_from Exception, :with => :server_error

    def server_error(exception)
      request.env['exception_notifier.options'] = {
        :sender_address => "notifier@example.com",
        :exception_recipients => "dev@example.com"
      }

      ExceptionNotifier::Notifier.exception_notification(
        request.env, exception
      ).deliver
    end

... which means code duplication, especially if you have more
than one action that's handling exceptions.

This commit should solve this problem by making the default
attributes writable and use the initial middleware configuration
to set those defaults to something more sensible.
smartinez87 added a commit that referenced this pull request Jun 9, 2011
Use values set for the middleware as defaults
@smartinez87 smartinez87 merged commit 27fbddd into smartinez87:master Jun 9, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants