class Warren::FrameworkAdaptor::RailsAdaptor::ConnectionMissing

Matches errors associated with database connection loss. To understand exactly how this works, we need to go under the hood of `rescue`. When an exception is raised in Ruby, the interpreter begins unwinding the stack, looking for `rescue` statements. For each one it finds it performs the check `ExceptionClass === raised_exception`, and if this returns true, it enters the rescue block, otherwise it continues unwinding the stack. Under normal circumstances Class#=== returns true for instances of that class. Here we override that behaviour and explicitly check for a database connection instead. This ensures that regardless of what exception gets thrown if we loose access to the database, we correctly handle the message

Public Class Methods

===(_) click to toggle source
# File lib/warren/framework_adaptor/rails_adaptor.rb, line 52
def self.===(_)
  # We used to inspect the exception, and try and check it against a list
  # of errors that might indicate connectivity issues. But this list
  # just grew and grew over time. So instead we just explicitly check
  # the outcome
  !ActiveRecord::Base.connection.active?
rescue StandardError => _e
  # Unfortunately ActiveRecord::Base.connection.active? can throw an
  # exception if it is unable to connect, and furthermore the class
  # depends on the adapter used.
  true
end