Commit 5be0265f authored by Sebastian Ziebell's avatar Sebastian Ziebell

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.
parent 41e93bbf
...@@ -4,6 +4,20 @@ module Gitlab ...@@ -4,6 +4,20 @@ module Gitlab
before { authenticate! } before { authenticate! }
resource :projects do 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 # Get a list of project milestones
# #
# Parameters: # Parameters:
...@@ -47,6 +61,7 @@ module Gitlab ...@@ -47,6 +61,7 @@ module Gitlab
if @milestone.save if @milestone.save
present @milestone, with: Entities::Milestone present @milestone, with: Entities::Milestone
else else
handle_milestone_errors(@milestone.errors)
not_found! not_found!
end end
end end
...@@ -70,6 +85,7 @@ module Gitlab ...@@ -70,6 +85,7 @@ module Gitlab
if @milestone.update_attributes attrs if @milestone.update_attributes attrs
present @milestone, with: Entities::Milestone present @milestone, with: Entities::Milestone
else else
handle_milestone_errors(@milestone.errors)
not_found! not_found!
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment