Add a global timeout that is applied to most API requests.
[rails.git] / app / controllers / application.rb
index 082c5cf65a28aceac9863bede1e0732e8f976b51..f166df21d6075be39651f9350e54106e3f85703b 100644 (file)
@@ -126,6 +126,12 @@ class ApplicationController < ActionController::Base
     raise OSM::APIBadMethodError.new(method) unless ok
   end
 
+  def api_call_timeout
+    Timeout::timeout(APP_CONFIG['api_timeout'], OSM::APITimeoutError) do
+      yield
+    end
+  end
+
 private 
 
   # extract authorisation credentials from headers, returns user = nil if none