Status code 400 returned if title not given in a milestone (via API)

If a milestone is created via API but no title given then status code 400 (Bad request)
is returned instead of 404. A small helper method handles the errors collection of a
milestone.
This commit is contained in:
Sebastian Ziebell 2013-02-06 15:03:05 +01:00
parent 41e93bbfe2
commit 5be0265fe7

View file

@ -4,6 +4,20 @@ module Gitlab
before { authenticate! }
resource :projects do
helpers do
# If an error occurs this helper method handles error codes for a given milestone
#
# Parameters:
# milestone_errors (required) - The erros collection of a milestone
#
def handle_milestone_errors(milestone_errors)
if milestone_errors[:title].any?
error!(milestone_errors[:title], 400)
end
end
end
# Get a list of project milestones
#
# Parameters:
@ -47,6 +61,7 @@ module Gitlab
if @milestone.save
present @milestone, with: Entities::Milestone
else
handle_milestone_errors(@milestone.errors)
not_found!
end
end
@ -70,6 +85,7 @@ module Gitlab
if @milestone.update_attributes attrs
present @milestone, with: Entities::Milestone
else
handle_milestone_errors(@milestone.errors)
not_found!
end
end