Class: ExceptionHub::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_hub/interceptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(exception, rack_env) ⇒ Interceptor

Returns a new instance of Interceptor.



3
4
5
6
# File 'lib/exception_hub/interceptor.rb', line 3

def initialize(exception, rack_env)
  @exception = exception
  @env = rack_env
end

Instance Method Details

#intercept!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/exception_hub/interceptor.rb', line 8

def intercept!
  if should_create_issue?
    n = ExceptionHub::Notifier.new(@exception, @env)
    ExceptionHub.before_create_exception_callbacks.each do |callback|
      callback.call(n, @env)
    end

    n.notify!

    ExceptionHub.after_create_exception_callbacks.each do |callback|
      callback.call(n, @env)
    end
  end
  self
end

#should_create_issue?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/exception_hub/interceptor.rb', line 24

def should_create_issue?
  return false if ExceptionHub.ignored_exceptions.include? @exception.class.name

  return true if defined?(::Rails) && ExceptionHub.reporting_environments.include?(::Rails.env.to_sym)
  return true if defined?(Sinatra::Base) && ExceptionHub.reporting_environments.include?(Sinatra::Base.environment)
  return true if ENV['RACK_ENV'] && ExceptionHub.reporting_environments.include?(ENV['RACK_ENV'].to_sym)
  #TODO Compare exception to YAML cache here
  false
end