From 080939c98724b039704ca8115ba610134d1edcff Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Tue, 16 Jul 2019 20:08:50 +0100 Subject: Raise specific exception on Mysql2::Error::TimeoutError --- .../lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 6 +++++- activerecord/lib/active_record/errors.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index e9ae8d159e..405fecb603 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -619,7 +619,11 @@ module ActiveRecord when ER_QUERY_INTERRUPTED QueryCanceled.new(message, sql: sql, binds: binds) else - super + if exception.is_a?(Mysql2::Error::TimeoutError) + ActiveRecord::AdapterTimeout.new(message, sql: sql, binds: binds) + else + super + end end end diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index c8c06375a3..012ff8c46f 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -365,6 +365,10 @@ module ActiveRecord class QueryCanceled < StatementInvalid end + # AdapterTimeout will be raised when database clients times out while waiting from the server + class AdapterTimeout < StatementInvalid + end + # UnknownAttributeReference is raised when an unknown and potentially unsafe # value is passed to a query method when allow_unsafe_raw_sql is set to # :disabled. For example, passing a non column name value to a relation's -- cgit v1.2.3