]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/amf_controller.rb
Add a global timeout that is applied to most API requests.
[rails.git] / app / controllers / amf_controller.rb
index 24093cd0907f45d356e6272d0c45b48400e122b4..f11700718556b95eec0b9f1a932dd027c64a43ed 100644 (file)
@@ -43,6 +43,7 @@ class AmfController < ApplicationController
 
   session :off
   before_filter :check_api_writable
+  around_filter :api_call_timeout, :only => [:amf_read]
 
   # Main AMF handlers: process the raw AMF string (using AMF library) and
   # calls each action (private method) accordingly.
@@ -72,7 +73,7 @@ class AmfController < ApplicationController
         index=AMF.getstring(req)                       #  | get index in response sequence
         bytes=AMF.getlong(req)                         #  | get total size in bytes
         args=AMF.getvalue(req)                         #  | get response (probably an array)
-        logger.info("Executing AMF #{message}:#{index}")
+        logger.info("Executing AMF #{message}(#{args.join(',')}):#{index}")
 
         case message
           when 'getpresets';           results[index]=AMF.putdata(index,getpresets())
@@ -89,7 +90,7 @@ class AmfController < ApplicationController
           when 'getpoi';               results[index]=AMF.putdata(index,getpoi(*args))
         end
       end
-      logger.info("encoding AMF results")
+      logger.info("Encoding AMF results")
       sendresponse(results)
     else
       render :nothing => true, :status => :method_not_allowed
@@ -133,7 +134,7 @@ class AmfController < ApplicationController
           when 'startchangeset';               results[index]=AMF.putdata(index,startchangeset(*args))
         end
       end
-      logger.info("encoding AMF results")
+      logger.info("Encoding AMF results")
       sendresponse(results)
     else
       render :nothing => true, :status => :method_not_allowed
@@ -198,7 +199,7 @@ class AmfController < ApplicationController
     enlarge = [(xmax-xmin)/8,0.01].min
     xmin -= enlarge; ymin -= enlarge
     xmax += enlarge; ymax += enlarge
-    
+
     # check boundary is sane and area within defined
     # see /config/application.yml
     check_boundaries(xmin, ymin, xmax, ymax)
@@ -228,6 +229,8 @@ class AmfController < ApplicationController
 
     [0, ways, points, relations]
 
+  rescue OSM::APITimeoutError => err
+    [-1,"Sorry - I can't get the map for that area. The server said: #{err}"]
   rescue Exception => err
     [-2,"Sorry - I can't get the map for that area. The server said: #{err}"]
   end