class ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ErrorHandler

Constants

CONNECTION_MATCHERS
HARSH_ERRORS

Public Instance Methods

connection_matchers() click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 50
def connection_matchers
  CONNECTION_MATCHERS
end
connection_message?(message) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 54
def connection_message?(message)
  message = message.to_s.downcase

  case message
  when *connection_matchers
    true
  else
    false
  end
end
custom_error_message?(connection, message) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 65
def custom_error_message?(connection, message)
  custom_error_matchers = connection._makara_custom_error_matchers
  return false if custom_error_matchers.empty?

  message = message.to_s

  custom_error_matchers.each do |matcher|
    if matcher.is_a?(String)

      # accept strings that look like "/.../" as a regex
      if matcher =~ /^\/(.+)\/([a-z])?$/

        options = $2 ? (($2.include?('x') ? Regexp::EXTENDED : 0) |
                  ($2.include?('i') ? Regexp::IGNORECASE : 0) |
                  ($2.include?('m') ? Regexp::MULTILINE : 0)) : 0

        matcher = Regexp.new($1, options)
      end
    end

    return true if matcher === message
  end

  false
end
handle(connection) { || ... } click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 30
def handle(connection)
  yield
rescue Exception => e
  # do it via class name to avoid version-specific constant dependencies
  case e.class.name
  when *harsh_errors
    harshly(e)
  else
    if connection_message?(e) || custom_error_message?(connection, e)
      gracefully(connection, e)
    else
      harshly(e)
    end
  end
end
harsh_errors() click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 46
def harsh_errors
  HARSH_ERRORS
end