Added better error messages on 412 precondition failed.
This commit is contained in:
parent
e8c7543bdd
commit
9ff7ea8d71
3 changed files with 26 additions and 24 deletions
|
@ -131,19 +131,21 @@ class Node < ActiveRecord::Base
|
||||||
# shouldn't be possible to get race conditions.
|
# shouldn't be possible to get race conditions.
|
||||||
Node.transaction do
|
Node.transaction do
|
||||||
check_consistency(self, new_node, user)
|
check_consistency(self, new_node, user)
|
||||||
if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = ? AND current_way_nodes.node_id = ?", true, self.id ])
|
way = WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id",
|
||||||
raise OSM::APIPreconditionFailedError.new
|
:conditions => [ "current_ways.visible = ? AND current_way_nodes.node_id = ?", true, self.id ])
|
||||||
elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Node' and member_id=? ", true, self.id])
|
raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by way #{way.id}.") unless way.nil?
|
||||||
raise OSM::APIPreconditionFailedError.new
|
|
||||||
else
|
|
||||||
self.changeset_id = new_node.changeset_id
|
|
||||||
self.visible = false
|
|
||||||
|
|
||||||
# update the changeset with the deleted position
|
rel = RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id",
|
||||||
changeset.update_bbox!(bbox)
|
:conditions => [ "visible = ? AND member_type='Node' and member_id=? ", true, self.id])
|
||||||
|
raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by way #{way.id}.") unless rel.nil?
|
||||||
|
|
||||||
save_with_history!
|
self.changeset_id = new_node.changeset_id
|
||||||
end
|
self.visible = false
|
||||||
|
|
||||||
|
# update the changeset with the deleted position
|
||||||
|
changeset.update_bbox!(bbox)
|
||||||
|
|
||||||
|
save_with_history!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -236,9 +236,9 @@ class Relation < ActiveRecord::Base
|
||||||
Relation.transaction do
|
Relation.transaction do
|
||||||
check_consistency(self, new_relation, user)
|
check_consistency(self, new_relation, user)
|
||||||
# This will check to see if this relation is used by another relation
|
# 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 ])
|
rel = 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("The relation #{new_relation.id} is a used in another relation")
|
raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in relation #{rel.id}.") unless rel.nil?
|
||||||
end
|
|
||||||
self.changeset_id = new_relation.changeset_id
|
self.changeset_id = new_relation.changeset_id
|
||||||
self.tags = {}
|
self.tags = {}
|
||||||
self.members = []
|
self.members = []
|
||||||
|
@ -249,8 +249,8 @@ class Relation < ActiveRecord::Base
|
||||||
|
|
||||||
def update_from(new_relation, user)
|
def update_from(new_relation, user)
|
||||||
check_consistency(self, new_relation, user)
|
check_consistency(self, new_relation, user)
|
||||||
if !new_relation.preconditions_ok?
|
unless preconditions_ok?
|
||||||
raise OSM::APIPreconditionFailedError.new
|
raise OSM::APIPreconditionFailedError.new("Cannot update relation #{self.id}: data or member data is invalid.")
|
||||||
end
|
end
|
||||||
self.changeset_id = new_relation.changeset_id
|
self.changeset_id = new_relation.changeset_id
|
||||||
self.changeset = new_relation.changeset
|
self.changeset = new_relation.changeset
|
||||||
|
@ -262,8 +262,8 @@ class Relation < ActiveRecord::Base
|
||||||
|
|
||||||
def create_with_history(user)
|
def create_with_history(user)
|
||||||
check_create_consistency(self, user)
|
check_create_consistency(self, user)
|
||||||
if !self.preconditions_ok?
|
unless self.preconditions_ok?
|
||||||
raise OSM::APIPreconditionFailedError.new
|
raise OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
|
||||||
end
|
end
|
||||||
self.version = 0
|
self.version = 0
|
||||||
self.visible = true
|
self.visible = true
|
||||||
|
|
|
@ -199,8 +199,8 @@ class Way < ActiveRecord::Base
|
||||||
|
|
||||||
def update_from(new_way, user)
|
def update_from(new_way, user)
|
||||||
check_consistency(self, new_way, user)
|
check_consistency(self, new_way, user)
|
||||||
if !new_way.preconditions_ok?
|
unless new_way.preconditions_ok?
|
||||||
raise OSM::APIPreconditionFailedError.new
|
raise OSM::APIPreconditionFailedError("Cannot update way #{self.id}: data is invalid.")
|
||||||
end
|
end
|
||||||
|
|
||||||
self.changeset_id = new_way.changeset_id
|
self.changeset_id = new_way.changeset_id
|
||||||
|
@ -213,8 +213,8 @@ class Way < ActiveRecord::Base
|
||||||
|
|
||||||
def create_with_history(user)
|
def create_with_history(user)
|
||||||
check_create_consistency(self, user)
|
check_create_consistency(self, user)
|
||||||
if !self.preconditions_ok?
|
unless self.preconditions_ok?
|
||||||
raise OSM::APIPreconditionFailedError.new
|
raise OSM::APIPreconditionFailedError("Cannot create way: data is invalid.")
|
||||||
end
|
end
|
||||||
self.version = 0
|
self.version = 0
|
||||||
self.visible = true
|
self.visible = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue