Class: RulesIO::Exceptions

Inherits:
Users show all
Includes:
Helpers
Defined in:
lib/rulesio/exceptions.rb

Instance Attribute Summary

Attributes inherited from Rack

#config_options, #controller_data, #filter_parameters

Attributes inherited from Base

#buffer, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#actor_for_exception, #clean_backtrace, #fileline, #from_crawler

Methods inherited from Rack

config_options, config_options=, #default_ignored_crawlers, #flush

Methods inherited from Base

#flush

Constructor Details

#initialize(app, options = {}) ⇒ Exceptions

Returns a new instance of Exceptions.



20
21
22
23
24
25
26
27
# File 'lib/rulesio/exceptions.rb', line 20

def initialize(app, options={})
  @app, @options = app, options
  @options[:ignore_exceptions] ||= self.class.default_ignored_exceptions
  @options[:ignore_crawlers]   ||= default_ignored_crawlers
  @options[:ignore_if]         ||= lambda { |env, e| false }
  @options[:token]             ||= RulesIO.token
  @options[:custom_data]       ||= lambda { |env| {} }
end

Class Method Details

.default_ignored_exceptionsObject



12
13
14
15
16
17
18
# File 'lib/rulesio/exceptions.rb', line 12

def self.default_ignored_exceptions
  [].tap do |exceptions|
    exceptions << 'ActiveRecord::RecordNotFound'
    exceptions << 'AbstractController::ActionNotFound'
    exceptions << 'ActionController::RoutingError'
  end
end

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/rulesio/exceptions.rb', line 29

def call(env)
  begin
    @app.call(env)
  rescue Exception => exception
    env['rulesio.exception'] = exception
    send_event event(env, exception), env unless should_be_ignored(env, exception)
    raise exception
  end
end

#send_event(event, env) ⇒ Object



39
40
41
42
# File 'lib/rulesio/exceptions.rb', line 39

def send_event(event, env)
  prep = prepare_event(event, env)
  RulesIO.post_payload_to_token prep, @options[:token]
end