Class: ChiliLogger::LoggingErrorHandler

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

Overview

class that handles errors when message broker can’t be reached, etc…

Instance Method Summary collapse

Constructor Details

#initialize(fallback_name, config) ⇒ LoggingErrorHandler

Returns a new instance of LoggingErrorHandler.



8
9
10
11
12
13
14
15
16
# File 'lib/errors/logging_error_handler/logging_error_handler.rb', line 8

def initialize(fallback_name, config)
  raise(ChiliLogger::ConfigError, ':fallback_broker_config must be present and be a hash') unless config.is_a?(Hash)

  fallback_name = fallback_name.to_sym if fallback_name
  fallback_broker_class = supported_fallback_brokers[fallback_name]
  unsupported_fallback_broker_error unless fallback_broker_class

  @fallback_broker = fallback_broker_class.new(config)
end

Instance Method Details

#handle_error(error, log = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/errors/logging_error_handler/logging_error_handler.rb', line 18

def handle_error(error, log = nil)
  message = message(error, log)
  @fallback_broker.publish(message)
rescue StandardError => e
  puts '
    There was a problem with both the Message Broker and the Fallback Broker simultaneously.
    To keep the application running and prevent downtime,
    ChiliLogger will ignore this errors and discard the log it was currently trying to publish.
    Please note that logs are being permanently lost.
  '
  puts e
end