Module: PgPower::ConnectionAdapters::PostgreSQLAdapter::TranslateException

Included in:
PgPower::ConnectionAdapters::PostgreSQLAdapter
Defined in:
lib/pg_power/connection_adapters/postgresql_adapter/translate_exception.rb

Overview

Extend ActiveRecord::ConnectionAdapter::PostgreSQLAdapter logic to wrap more pg-specific errors into specific exception classes

Constant Summary collapse

INSUFFICIENT_PRIVILEGE =
"42501"

Instance Method Summary collapse

Instance Method Details

#translate_exception(exception, message) ⇒ Object

Intercept insufficient privilege PGError and raise active_record wrapped database exception



8
9
10
11
12
13
14
15
16
17
# File 'lib/pg_power/connection_adapters/postgresql_adapter/translate_exception.rb', line 8

def translate_exception(exception, message)
  case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE)
    when INSUFFICIENT_PRIVILEGE
      exc_message = exception.result.try(:error_field, PGresult::PG_DIAG_MESSAGE_PRIMARY)
      exc_message ||= message
      ::ActiveRecord::InsufficientPrivilege.new(exc_message, exception)
    else
      super
  end
end