class ScoutApm::ErrorService::IgnoredExceptions

Attributes

blocks[R]
ignored_exceptions[R]

Public Class Methods

new(context, from_config) click to toggle source
# 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

Public Instance Methods

add(klass_or_str) click to toggle source

Add a single ignored exception by class name

# 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) click to toggle source

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

# File lib/scout_apm/error_service/ignored_exceptions.rb, line 22
def add_callback(&block)
  @blocks << block
end
ignored?(exception_object) click to toggle source
# 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

Private Instance Methods

normalize_as_klass(klass_or_str) click to toggle source
# File lib/scout_apm/error_service/ignored_exceptions.rb, line 46
def normalize_as_klass(klass_or_str)
  if Module === klass_or_str
    return klass_or_str
  end

  if klass_or_str.is_a?(Exception)
    return klass_or_str.class
  end

  if String === klass_or_str
    maybe = ScoutApm::Utils::KlassHelper.lookup(klass_or_str)
    if Module === maybe
      return maybe
    end
  end

  klass_or_str
end