class Rack::ExceptionNotifier
Constants
- ExcludeBodyKeys
- Template
- VERSION
Public Class Methods
new(app, options)
click to toggle source
# File lib/rack/exception_notifier.rb, line 8 def initialize(app, options) default_options = { :to => nil, :from => ENV['USER'] || 'rack@localhost', :subject => '[ERROR] %s', :include_body => false } @app = app @options = default_options.merge(options) if @options[:to].nil? raise ArgumentError.new('to address is required') end end
Public Instance Methods
_body_present?(env)
click to toggle source
# File lib/rack/exception_notifier.rb, line 42 def _body_present?(env) _extract_body(env, 1) end
_exclude_env_key?(env, key)
click to toggle source
# File lib/rack/exception_notifier.rb, line 46 def _exclude_env_key?(env, key) if _render_body?(env) false else ExcludeBodyKeys.include?(key) end end
_extract_body(env, length = nil)
click to toggle source
# File lib/rack/exception_notifier.rb, line 58 def _extract_body(env, length = nil) io = env['rack.input'] io.rewind io.read(length) end
_render_body?(env)
click to toggle source
# File lib/rack/exception_notifier.rb, line 54 def _render_body?(env) _body_present?(env) && @options[:include_body] end
_send_notification(exception, env)
click to toggle source
# File lib/rack/exception_notifier.rb, line 30 def _send_notification(exception, env) template = ERB.new(Template) mail = Mail.new mail.to(@options[:to]) mail.reply_to(@options[:reply_to]) mail.from(@options[:from]) mail.subject(@options[:subject] % [exception.to_s]) mail.body(template.result(binding)) mail.deliver! end
call(env)
click to toggle source
# File lib/rack/exception_notifier.rb, line 23 def call(env) @app.call(env) rescue => e _send_notification(e, env) raise end