smartinez87/exception_notification — pull request #127 by ProGNOMmers (2013-02-25 10:38:18+00:00)
Title: Adding :notifier_proc option

Hello,

I have the needing to customize the notifier processing (I manage the email sending using DelayedJob), so I added a `notifier_proc` option, which I use it in this way:

```ruby
module EasyMarshalDumpableHash
def self.easy_marshal_dumpable_hash(hash)
Hash[ hash.map do |k, v|
[ k,
if v.is_a?(Hash)
easy_marshal_dumpable_hash(v)
else
begin
Marshal.dump(v)
v
rescue TypeError
v.inspect
end
end ]
end ]
end
end

class ControllerInfo
attr_reader :controller_name, :action_name

def initialize(controller_name, action_name)
@controller_name, @action_name = controller_name, action_name
end
end

Desy::Application.configure do
# ExceptionNotifier configuration
config.middleware.use ExceptionNotifier,
notifier_proc: ->(env, exception) do
md_env = EasyMarshalDumpableHash.easy_marshal_dumpable_hash(env)
md_env['action_controller.instance'] = ControllerInfo.new(env['action_controller.instance'].controller_name, env['action_controller.instance'].action_name)

Delayed::Job.enqueue ExceptionNotifierJob.new(md_env, exception)
end
end
```

(The part before the configuration is not interesting, I added it just to make a working example).

Maybe this feature could be useful to other people, since it makes the sending management more flexible.

Feel free to tell me to fix some code (style, test, docs...) or do it yourself at your pleasure.