Commit 5be0265fe7e82a127e9fd2805e81e4e40f5e3c5f
1 parent
41e93bbf
Exists in
master
and in
4 other branches
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.
Showing
1 changed file
with
16 additions
and
0 deletions
Show diff stats
lib/api/milestones.rb
... | ... | @@ -4,6 +4,20 @@ module Gitlab |
4 | 4 | before { authenticate! } |
5 | 5 | |
6 | 6 | resource :projects do |
7 | + | |
8 | + helpers do | |
9 | + # If an error occurs this helper method handles error codes for a given milestone | |
10 | + # | |
11 | + # Parameters: | |
12 | + # milestone_errors (required) - The erros collection of a milestone | |
13 | + # | |
14 | + def handle_milestone_errors(milestone_errors) | |
15 | + if milestone_errors[:title].any? | |
16 | + error!(milestone_errors[:title], 400) | |
17 | + end | |
18 | + end | |
19 | + end | |
20 | + | |
7 | 21 | # Get a list of project milestones |
8 | 22 | # |
9 | 23 | # Parameters: |
... | ... | @@ -47,6 +61,7 @@ module Gitlab |
47 | 61 | if @milestone.save |
48 | 62 | present @milestone, with: Entities::Milestone |
49 | 63 | else |
64 | + handle_milestone_errors(@milestone.errors) | |
50 | 65 | not_found! |
51 | 66 | end |
52 | 67 | end |
... | ... | @@ -70,6 +85,7 @@ module Gitlab |
70 | 85 | if @milestone.update_attributes attrs |
71 | 86 | present @milestone, with: Entities::Milestone |
72 | 87 | else |
88 | + handle_milestone_errors(@milestone.errors) | |
73 | 89 | not_found! |
74 | 90 | end |
75 | 91 | end | ... | ... |