Class: Eras::ErrorReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/eras/error_reporter.rb

Instance Method Summary collapse

Instance Method Details

#cleanerObject



34
35
36
37
38
39
40
# File 'lib/eras/error_reporter.rb', line 34

def cleaner
  @cleaner ||= begin
    cleaner = ActiveSupport::BacktraceCleaner.new
    cleaner.add_silencer { |line| line =~ %r{eras/error_reporter.rb} }
    cleaner
  end
end

#report(error, handled:, severity:, context:, source: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eras/error_reporter.rb', line 3

def report(error, handled:, severity:, context:, source: nil)
  return if Eras.config.ignored_error_classes.include?(error.class.name)
  return unless Eras.config.reporting_envs.include?(::Rails.env)

  context = context.merge(rails_env: ::Rails.env).transform_values(&:to_s)
  kaller = caller

  data = {
    handled: handled,
    severity: severity,
    context: context,
    source: source
  }.tap do |d|
    # This doesn't feel very elegant, but it'll do for now
    d[:error] = if error.is_a?(Exception)
                  {
                    title: error.class.name,
                    message: error.message,
                    backtrace: error.backtrace&.join("\n")
                  }
                else
                  {
                    title: "[message]",
                    message: error,
                    backtrace: cleaner.clean(kaller).join("\n")
                  }
                end
  end
  Eras.adapter.write_error(data)
end