X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/bbd769304cf29bbd9574fd3c7167feb7d5d0aa17..cf78f3e6ddbd1c148e91de6500266240bfa24825:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index bd9351026..c038ab2d5 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -10,6 +10,9 @@ module OSM # The base class for API Errors. class APIError < RuntimeError + def render_opts + { :text => "", :status => :internal_server_error } + end end # Raised when an API object is not found. @@ -18,10 +21,30 @@ module OSM # Raised when a precondition to an API action fails sanity check. class APIPreconditionFailedError < APIError + def render_opts + { :text => "", :status => :precondition_failed } + end end # Raised when to delete an already-deleted object. class APIAlreadyDeletedError < APIError + def render_opts + { :text => "", :status => :gone } + end + end + + # Raised when the provided version is not equal to the latest in the db. + class APIVersionMismatchError < APIError + def initialize(provided, latest) + @provided, @latest = provided, latest + end + + attr_reader :provided, :latest + + def render_opts + { :text => "Version mismatch: Provided " + provided.to_s + + ", server had: " + latest.to_s, :status => :bad_request } + end end # Helper methods for going to/from mercator and lat/lng.