public
Description: Exception Handler is a Redmine plugin that can be configured to send Exception notification emails when an error occurs in Redmine.
Homepage: https://projects.littlestreamsoftware.com/projects/show/redmine-exception
Clone URL: git://github.com/edavis10/redmine-exception-handler-plugin.git
100644 47 lines (37 sloc) 1.805 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'redmine'
 
Dir[File.join(directory,'vendor','plugins','*')].each do |dir|
  path = File.join(dir, 'lib')
  $LOAD_PATH << path
  ActiveSupport::Dependencies.load_paths << path
  ActiveSupport::Dependencies.load_once_paths.delete(path)
end
 
Redmine::Plugin.register :redmine_exception_handler_plugin do
  name 'Redmine Exception Handler plugin'
  author 'Eric Davis'
  description 'Send emails when exceptions occur in Redmine.'
  version '0.2.0'
  
  settings :default => {
    'exception_handler_recipients' => 'you@example.com, another@example.com',
    'exception_handler_sender_address' => 'Application Error <redmine@example.com>',
    'exception_handler_prefix' => '[ERROR]'
  }, :partial => 'settings/exception_handler_settings'
  
end
 
require_dependency 'exception_notifier'
 
module RedmineExceptionNotifierPatch
  def self.included(target)
    target.send(:include, InstanceMethods)
  end
 
  module InstanceMethods
    def exception_notification_with_database(exception, controller, request, data={}, &block)
      if Object.const_defined?('Setting')
        ExceptionNotifier.exception_recipients = Setting.plugin_redmine_exception_handler_plugin['exception_handler_recipients'].split(',').map { |name| name.strip }
        ExceptionNotifier.sender_address = Setting.plugin_redmine_exception_handler_plugin['exception_handler_sender_address']
        ExceptionNotifier.email_prefix = Setting.plugin_redmine_exception_handler_plugin['exception_handler_prefix']
      end
      exception_notification_without_database(exception, controller, request, data, &block)
    end
 
  end
  
end
ExceptionNotifier.send(:include, RedmineExceptionNotifierPatch)
ExceptionNotifier.send(:alias_method_chain, :exception_notification, :database)
ActionController::Base.send(:include, ExceptionNotifiable)