Class: ScoutApm::ErrorService::IgnoredExceptions

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/error_service/ignored_exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, from_config) ⇒ IgnoredExceptions

Returns a new instance of IgnoredExceptions.



9
10
11
12
13
# File 'lib/scout_apm/error_service/ignored_exceptions.rb', line 9

def initialize(context, from_config)
  @context = context
  @ignored_exceptions = Array(from_config).map{ |e| normalize_as_klass(e) }
  @blocks = []
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



7
8
9
# File 'lib/scout_apm/error_service/ignored_exceptions.rb', line 7

def blocks
  @blocks
end

#ignored_exceptionsObject (readonly)

Returns the value of attribute ignored_exceptions.



6
7
8
# File 'lib/scout_apm/error_service/ignored_exceptions.rb', line 6

def ignored_exceptions
  @ignored_exceptions
end

Instance Method Details

#add(klass_or_str) ⇒ Object

Add a single ignored exception by class name



16
17
18
# File 'lib/scout_apm/error_service/ignored_exceptions.rb', line 16

def add(klass_or_str)
  @ignored_exceptions << normalize_as_klass(klass_or_str)
end

#add_callback(&block) ⇒ Object

Add a callback block that will be called on every error. If it returns Signature of blocks: ->(exception object): truthy or falsy value



22
23
24
# File 'lib/scout_apm/error_service/ignored_exceptions.rb', line 22

def add_callback(&block)
  @blocks << block
end

#ignored?(exception_object) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scout_apm/error_service/ignored_exceptions.rb', line 26

def ignored?(exception_object)
  klass = normalize_as_klass(exception_object)

  # Check if we ignored this error by name (typical way to ignore)
  if ignored_exceptions.any? { |ignored| klass.ancestors.include?(ignored) }
    return true
  end

  # For each block, see if it says we should ignore this error
  blocks.each do |b|
    if b.call(exception_object)
      return true
    end
  end

  false
end