diff --git a/lib/exception_notifier/notifier.rb b/lib/exception_notifier/notifier.rb index eb11b5f2..70e489df 100644 --- a/lib/exception_notifier/notifier.rb +++ b/lib/exception_notifier/notifier.rb @@ -66,6 +66,23 @@ def exception_notification(env, exception) end end + def background_exception_notification(exception) + + if @notifier = Rails.application.config.middleware.detect { |x| x.klass == ExceptionNotifier } + @options = (@notifier.args.first || {}).reverse_merge(self.class.default_options) + subject = "#{@options[:email_prefix]} (#{exception.class}) #{exception.message.inspect}" + + @exception = exception + @backtrace = exception.backtrace || [] + @sections = %w{backtrace} + + mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format| + format.text { render "#{mailer_name}/background_exception_notification" } + end.deliver + end + end + + private def clean_backtrace(exception) diff --git a/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb b/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb new file mode 100644 index 00000000..c27dc21f --- /dev/null +++ b/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb @@ -0,0 +1,13 @@ +A <%= @exception.class %> occurred in background: + + <%= @exception.message %> + <%= @backtrace.first %> + + <% sections = @sections.map do |section| + summary = render(section).strip + unless summary.blank? + title = render("title", :title => section).strip + "#{title}\n\n#{summary.gsub(/^/, " ")}\n\n" + end + end %> + <%= raw sections.join %>