mirror of
https://github.com/github/rails.git
synced 2026-01-10 23:27:56 -05:00
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:
committed by
Jon Leighton
parent
517060ab59
commit
be913c3964
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user