From: Shaun McDonald Date: Tue, 25 Nov 2008 18:59:35 +0000 (+0000) Subject: Some improvements to the error messages that are returned by the api. X-Git-Tag: live~7573^2~128 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/8348493ccb02fd0bb3f46733d8176b503f9f9883?ds=inline Some improvements to the error messages that are returned by the api. --- diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index 5e538c721..d7764d995 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -294,6 +294,7 @@ class ChangesetController < ApplicationController render ex.render_opts end +private #------------------------------------------------------------ # utility functions below. #------------------------------------------------------------ diff --git a/app/controllers/relation_controller.rb b/app/controllers/relation_controller.rb index 575cca419..93573b95f 100644 --- a/app/controllers/relation_controller.rb +++ b/app/controllers/relation_controller.rb @@ -64,7 +64,6 @@ class RelationController < ApplicationController end def delete -#XXX check if member somewhere! begin relation = Relation.find(params[:id]) new_relation = Relation.from_xml(request.raw_post) @@ -143,8 +142,7 @@ class RelationController < ApplicationController render :text => doc.to_s, :content_type => "text/xml" else - - render :text => "", :status => :gone + render :nothing => true, :status => :gone end rescue ActiveRecord::RecordNotFound @@ -167,8 +165,10 @@ class RelationController < ApplicationController render :text => doc.to_s, :content_type => "text/xml" else - render :nothing => true, :status => :bad_request + render :text => "You need to supply a comma separated list of ids.", :status => :bad_request end + rescue ActiveRecord::RecordNotFound + render :text => "Could not find one of the relations", :status => :not_found end def relations_for_way diff --git a/app/models/relation.rb b/app/models/relation.rb index 19548f20c..0159c60b8 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -35,7 +35,6 @@ class Relation < ActiveRecord::Base return Relation.from_xml_node(pt, create) end rescue LibXML::XML::Error => ex - #return nil raise OSM::APIBadXMLError.new("relation", xml, ex.message) end end @@ -47,16 +46,18 @@ class Relation < ActiveRecord::Base relation.id = pt['id'].to_i end - relation.version = pt['version'] + raise OSM::APIBadXMLError.new("relation", pt, "You are missing the required changeset in the relation") if pt['changeset'].nil? relation.changeset_id = pt['changeset'] if create relation.timestamp = Time.now relation.visible = true + relation.version = 0 else if pt['timestamp'] relation.timestamp = Time.parse(pt['timestamp']) end + relation.version = pt['version'] end pt.find('tag').each do |tag| @@ -348,15 +349,15 @@ class Relation < ActiveRecord::Base def delete_with_history!(new_relation, user) if self.visible check_consistency(self, new_relation, user) + # This will check to see if this relation is used by another relation if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='relation' and member_id=? ", true, self.id ]) - raise OSM::APIPreconditionFailedError.new - else - self.changeset_id = new_relation.changeset_id - self.tags = {} - self.members = [] - self.visible = false - save_with_history! + raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in another relation") end + self.changeset_id = new_relation.changeset_id + self.tags = {} + self.members = [] + self.visible = false + save_with_history! else raise OSM::APIAlreadyDeletedError.new end diff --git a/test/functional/relation_controller_test.rb b/test/functional/relation_controller_test.rb index b8d15e529..4ace316a4 100644 --- a/test/functional/relation_controller_test.rb +++ b/test/functional/relation_controller_test.rb @@ -276,7 +276,8 @@ class RelationControllerTest < ActionController::TestCase # try to delete without specifying a changeset content "" delete :delete, :id => current_relations(:visible_relation).id - assert_response :conflict + assert_response :bad_request + assert_match(/You are missing the required changeset in the relation/, @response.body) # try to delete with an invalid (closed) changeset content update_changeset(current_relations(:visible_relation).to_xml,