Skip to content

Commit e7fa5ea

Browse files
committed
allow AC instance to be nil
1 parent 006be77 commit e7fa5ea

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/exception_notifier/notifier.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ def default_options
3131
end
3232
end
3333

34+
class MissingController
35+
def method_missing(*args, &block)
36+
end
37+
end
38+
3439
def exception_notification(env, exception)
3540
@env = env
3641
@exception = exception
3742
@options = (env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
38-
@controller = env['action_controller.instance']
43+
@controller = env['action_controller.instance'] || MissingController.new
3944
@request = ActionDispatch::Request.new(env)
4045
@backtrace = clean_backtrace(exception)
4146
@sections = @options[:sections]
@@ -47,7 +52,7 @@ def exception_notification(env, exception)
4752

4853
prefix = "#{@options[:email_prefix]}#{@controller.controller_name}##{@controller.action_name}"
4954
subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}"
50-
55+
5156
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
5257
format.text { render "#{mailer_name}/exception_notification" }
5358
end

0 commit comments

Comments
 (0)