]> git.openstreetmap.org Git - rails.git/commitdiff
Monkey patch rails to ensure OSM::APITimeoutError exceptions are not lost.
authorTom Hughes <tom@compton.nu>
Thu, 21 May 2009 09:57:21 +0000 (09:57 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 21 May 2009 09:57:21 +0000 (09:57 +0000)
config/initializers/abstract_adapter.rb [new file with mode: 0644]

diff --git a/config/initializers/abstract_adapter.rb b/config/initializers/abstract_adapter.rb
new file mode 100644 (file)
index 0000000..7b22a3c
--- /dev/null
@@ -0,0 +1,24 @@
+module ActiveRecord
+  module ConnectionAdapters
+    class AbstractAdapter
+    protected
+      alias_method :old_log, :log
+
+      def log(sql, name)
+        if block_given?
+          old_log(sql, name) do
+            yield
+          end
+        else
+          old_log(sql, name)
+        end
+      rescue ActiveRecord::StatementInvalid => ex
+        if ex =~ /^OSM::APITimeoutError: /
+          raise OSM::APITimeoutError
+        else
+          raise
+        end
+      end
+    end
+  end
+end