Class: Croaker::Swallower

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error:, note:, logger: Rails.logger) ⇒ Swallower

Returns a new instance of Swallower.



10
11
12
13
14
# File 'lib/croaker.rb', line 10

def initialize(error:, note:, logger: Rails.logger)
  @error = error
  @logger = logger
  @note = note
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



16
17
18
# File 'lib/croaker.rb', line 16

def error
  @error
end

#loggerObject (readonly)

Returns the value of attribute logger.



16
17
18
# File 'lib/croaker.rb', line 16

def logger
  @logger
end

#noteObject (readonly)

Returns the value of attribute note.



16
17
18
# File 'lib/croaker.rb', line 16

def note
  @note
end

Instance Method Details

#callObject



18
19
20
21
# File 'lib/croaker.rb', line 18

def call
  log(error: error, note: note)
  capture(error)
end

#capture(error) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/croaker.rb', line 33

def capture(error)
  if capturer
    capturer.capture_error(error)
  else
    logger.tagged("Croaker") do
      logger.info "Not capturing this error - no error capturing service registered."
    end
  end
end

#log(error:, note:) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/croaker.rb', line 23

def log(error:, note:)
  message = "Unhandled error: [#{note}] [#{error.message}]"

  message += " #{error.backtrace.first}" if error.backtrace

  logger.tagged("Croaker") do
    logger.error message
  end
end