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:
parent
41e93bbfe2
commit
5be0265fe7
1 changed files with 16 additions and 0 deletions
|
@ -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
|
||||||
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
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue