I want to be able to define the exception_recipients dynamically, based on the Rails environment. For example:
recipients = Rails.env == 'production'
[email protected]
else
User.current.email
end
However, from the docs:
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier" <[email protected]>},
:exception_recipients => %w{[email protected]}
}
In config/environments/production.rb where i don't have an ActiveRecord::Base connection yet.
How can I set the exceptions recipients after Rails has loaded?
Thanks
Custom Notifier
You can create a custom notifier, which inherits from the
EmailNotifier, which will useUser.current.emailin the non-production environments.Initializer
The fallback address can, for example, be passed from the initializer.
current_userinstead ofUser.currentI'm not sure whether your
User.currentcall will work here. But, you pass thecurrent_userto the exception data as shown in the README.Then, replace the above
ExceptionNotifier::CustomNotifier#callmethod with this one: