Don't crash exception translation w/ nil result attribute.

Exception.result is nil when attempting a query after PostgreSQL
disconnect, resulting in new exception:
NoMethodError: undefined method `error_field' for nil:NilClass
This commit is contained in:
Steve Jorgensen
2012-05-21 09:50:29 -07:00
committed by Jon Leighton
parent 517060ab59
commit be913c3964

View File

@@ -1144,7 +1144,7 @@ module ActiveRecord
UNIQUE_VIOLATION = "23505"
def translate_exception(exception, message)
case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE)
case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE)
when UNIQUE_VIOLATION
RecordNotUnique.new(message, exception)
when FOREIGN_KEY_VIOLATION