Class: WhenAUser::Exceptions

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/whenauser/exceptions.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#actor_for_exception, #clean_backtrace, #from_crawler

Constructor Details

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

Returns a new instance of Exceptions.



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

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

Class Method Details

.default_ignored_exceptionsObject



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

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



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

def call(env)
  begin
    @app.call(env)
  rescue Exception => exception
    env['whenauser.exception'] = exception
    send_event_now event(env, exception), @options[:token], env unless should_be_ignored(env, exception)
    raise exception
  end
end