X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/bbd769304cf29bbd9574fd3c7167feb7d5d0aa17..7151fa05e4d4f73956d7f9a7ad2db1f5b956a0c0:/lib/osm.rb diff --git a/lib/osm.rb b/lib/osm.rb index bd9351026..8798866e5 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -10,6 +10,7 @@ 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 +19,26 @@ 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 " + ex.provided.to_s + + ", server had: " + ex.latest.to_s, :status => :bad_request } + end end # Helper methods for going to/from mercator and lat/lng.