Class: ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ErrorHandler
- Inherits:
-
Makara::ErrorHandler
- Object
- Makara::ErrorHandler
- ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ErrorHandler
- Defined in:
- lib/active_record/connection_adapters/makara_abstract_adapter.rb
Constant Summary collapse
- HARSH_ERRORS =
[ 'ActiveRecord::RecordNotUnique', 'ActiveRecord::InvalidForeignKey', 'Makara::Errors::BlacklistConnection' ].map(&:freeze).freeze
- CONNECTION_MATCHERS =
[ /(closed|lost|no|terminating|terminated)\s?([^\s]+)?\sconnection/, /gone away/, /connection[^:]+refused/, /could not connect/, /can\'t connect/, /cannot connect/, /connection[^:]+closed/, /can\'t get socket descriptor/, /connection to [a-z0-9.]+:[0-9]+ refused/, /timeout expired/, /could not translate host name/, /timeout waiting for a response/, /the database system is (starting|shutting)/ ].map(&:freeze).freeze
Instance Method Summary collapse
- #connection_matchers ⇒ Object
- #connection_message?(message) ⇒ Boolean
- #custom_error_message?(connection, message) ⇒ Boolean
- #handle(connection) ⇒ Object
- #harsh_errors ⇒ Object
Instance Method Details
#connection_matchers ⇒ Object
50 51 52 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 50 def connection_matchers CONNECTION_MATCHERS end |
#connection_message?(message) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 54 def () = .to_s.downcase case when *connection_matchers true else false end end |
#custom_error_message?(connection, message) ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 65 def (connection, ) custom_error_matchers = connection._makara_custom_error_matchers return false if custom_error_matchers.empty? = .to_s custom_error_matchers.each do |matcher| if matcher.is_a?(String) # accept strings that look like "/.../" as a regex if matcher =~ /^\/(.+)\/([a-z])?$/ = $2 ? (($2.include?('x') ? Regexp::EXTENDED : 0) | ($2.include?('i') ? Regexp::IGNORECASE : 0) | ($2.include?('m') ? Regexp::MULTILINE : 0)) : 0 matcher = Regexp.new($1, ) end end return true if matcher === end false end |
#handle(connection) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 30 def handle(connection) yield rescue Exception => e # do it via class name to avoid version-specific constant dependencies case e.class.name when *harsh_errors harshly(e) else if (e) || (connection, e) gracefully(connection, e) else harshly(e) end end end |
#harsh_errors ⇒ Object
46 47 48 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 46 def harsh_errors HARSH_ERRORS end |