class Xcflushd::FlusherErrorHandler

Constants

AUTHORIZER_ERRORS
NON_TEMP_ERRORS
REPORTER_ERRORS
STORAGE_ERRORS
TEMP_ERRORS

Attributes

logger[R]
storage[R]

Public Class Methods

new(logger, storage) click to toggle source
# File lib/xcflushd/flusher_error_handler.rb, line 27
def initialize(logger, storage)
  @logger = logger
  @storage = storage
end

Public Instance Methods

handle_auth_errors(failed_auths) click to toggle source

@param failed_auths [Hash<Auth, Exception>]

# File lib/xcflushd/flusher_error_handler.rb, line 39
def handle_auth_errors(failed_auths)
  failed_auths.values.each { |exception| log(exception) }
end
handle_renew_auth_error(exception) click to toggle source

@param exception [Exception]

# File lib/xcflushd/flusher_error_handler.rb, line 44
def handle_renew_auth_error(exception)
  # Failing to renew an authorization in the cache should not be a big
  # problem. It is probably caused by a temporary issue (like a Redis
  # connection error) and the auth will probably be successfully renewed
  # next time. So for now, we just log the error.
  log(exception)
end
handle_report_errors(failed_reports) click to toggle source

@param failed_reports [Hash<Report, Exception>]

# File lib/xcflushd/flusher_error_handler.rb, line 33
def handle_report_errors(failed_reports)
  failed_reports.values.each { |exception| log(exception) }
  storage.report(failed_reports.keys)
end

Private Instance Methods

error_msg(exception) click to toggle source
# File lib/xcflushd/flusher_error_handler.rb, line 73
def error_msg(exception)
  "#{exception.message} Cause: #{exception.cause || '-'.freeze}"
end
log(exception) click to toggle source

For exceptions that are likely to require the user intervention, we log errors. For example, when the report could not be made because the 3scale client received an invalid provider key. On the other hand, for errors that are likely to be temporary, like when we could not connect with 3scale, we log a warning.

# File lib/xcflushd/flusher_error_handler.rb, line 61
def log(exception)
  msg = error_msg(exception)
  case exception
    when *NON_TEMP_ERRORS
      logger.error(msg)
    when *TEMP_ERRORS
      logger.warn(msg)
    else
      logger.error(msg)
  end
end