X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/b56f57ec43dfefa4171dc0cefe26d9e75d4ca2bc..635daf1773f5e2795c87619aa527adde965ce938:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index ae8b81f5b..b002ebbe8 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -54,6 +54,32 @@ module OSM end end + # Raised when a diff is uploaded containing many changeset IDs which don't match + # the changeset ID that the diff was uploaded to. + class APIChangesetMismatchError < APIError + def initialize(provided, allowed) + @provided, @allowed = provided, allowed + end + + def render_opts + { :text => "Changeset mismatch: Provided #{@provided} but only " + + "#{@allowed} is allowed.", :status => :conflict } + end + end + + # Raised when bad XML is encountered which stops things parsing as + # they should. + class APIBadXMLError < APIError + def initialize(model, xml) + @model, @xml = model, xml + end + + def render_opts + { :text => "Cannot parse valid #{@model} from xml string #{@xml}", + :status => :bad_request } + end + end + # Raised when the provided version is not equal to the latest in the db. class APIVersionMismatchError < APIError def initialize(provided, latest) @@ -82,6 +108,21 @@ module OSM :status => :bad_request } end end + + # Raised when a way has more than the configured number of way nodes. + # This prevents ways from being to long and difficult to work with + class APITooManyWayNodesError < APIError + def initialize(provided, max) + @provided, @max = provided, max + end + + attr_reader :provided, :max + + def render_opts + { :text => "You tried to add #{provided} nodes to the way, however only #{max} are allowed", + :status => :bad_request } + end + end # Helper methods for going to/from mercator and lat/lng. class Mercator @@ -249,7 +290,7 @@ module OSM doc.encoding = 'UTF-8' root = XML::Node.new 'osm' root['version'] = API_VERSION - root['generator'] = 'OpenStreetMap server' + root['generator'] = GENERATOR doc.root = root return doc end