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.
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)
[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
session :off
before_filter :check_api_readable, :except => [:capabilities]
after_filter :compress_output
+ around_filter :api_call_handle_error, :api_call_timeout
# Help methods for checking boundary sanity and area size
include MapBoundary
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
before_filter :check_api_writable, :only => [:create, :update, :delete]
before_filter :check_api_readable, :except => [:create, :update, :delete]
after_filter :compress_output
- around_filter :api_call_handle_error
+ around_filter :api_call_handle_error, :api_call_timeout
# Create a node from XML.
def create
session :off
before_filter :check_api_readable
after_filter :compress_output
- around_filter :api_call_handle_error
+ around_filter :api_call_handle_error, :api_call_timeout
def history
node = Node.find(params[:id])
session :off
before_filter :check_api_readable
after_filter :compress_output
- around_filter :api_call_handle_error
+ around_filter :api_call_handle_error, :api_call_timeout
def history
relation = Relation.find(params[:id])
session :off
before_filter :check_api_readable
after_filter :compress_output
- around_filter :api_call_handle_error
+ around_filter :api_call_handle_error, :api_call_timeout
def history
way = Way.find(params[:id])
before_filter :check_api_writable, :only => [:create, :update, :delete]
before_filter :check_api_readable, :except => [:create, :update, :delete]
after_filter :compress_output
- around_filter :api_call_handle_error
+ around_filter :api_call_handle_error, :api_call_timeout
def create
assert_method :put
before_filter :check_api_writable, :only => [:create, :update, :delete]
before_filter :check_api_readable, :except => [:create, :update, :delete]
after_filter :compress_output
- around_filter :api_call_handle_error
+ around_filter :api_call_handle_error, :api_call_timeout
def create
assert_method :put
postcode_zoom: 15
# Zoom level to use for geonames results from the geocoder
geonames_zoom: 12
+ # Timeout for API calls in seconds
+ api_timeout: 300
development:
<<: *standard_settings
end
end
+ ##
+ # raised when an API call takes too long
+ class APITimeoutError < APIError
+ def render_opts
+ { :text => "Request timed out", :status => :request_timeout }
+ end
+
+ def to_s
+ "Request timed out"
+ end
+ end
+
# Helper methods for going to/from mercator and lat/lng.
class Mercator
include Math