From: Tom Hughes Date: Fri, 2 Dec 2016 09:42:05 +0000 (+0000) Subject: Simplify monkey patch X-Git-Tag: live~3710 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c129a8eec5b0762d75372bc6c07704d49453fed1 Simplify monkey patch The log method has grown new arguments which we weren't passing on, but fortunately the exception translation is now delegated to another method so we can patch that instead. --- diff --git a/config/initializers/abstract_adapter.rb b/config/initializers/abstract_adapter.rb index 89d384567..6bb5d10c0 100644 --- a/config/initializers/abstract_adapter.rb +++ b/config/initializers/abstract_adapter.rb @@ -6,23 +6,15 @@ if defined?(ActiveRecord::ConnectionAdaptors::AbstractAdapter) alias old_log log - def log(sql, name) - if block_given? - old_log(sql, name) do - yield - end + def translate_exception_class_with_timeout(e, sql) + if e.is_a?(Timeout::Error) || e.is_a?(OSM::APITimeoutError) + e else - old_log(sql, name) - end - rescue ActiveRecord::StatementInvalid => ex - if ex.message =~ /^OSM::APITimeoutError: / - raise OSM::APITimeoutError.new - elsif ex.message =~ /^Timeout::Error: / - raise Timeout::Error.new("time's up!") - else - raise + translate_exception_class_without_timeout(e, sql) end end + + alias_method_chain :translate_exception_class, :timeout end end end