summaryrefslogtreecommitdiff
path: root/lib/api/labels.rb
diff options
context:
space:
mode:
authorjubianchi <contact@jubianchi.fr>2014-08-18 20:09:09 +0200
committerjubianchi <contact@jubianchi.fr>2014-09-16 01:25:24 +0200
commit998cd3cb63d56a0058c8e519d7c20e3d6e540899 (patch)
tree38b9319858451f8bbebc7670e5505a7f1e6665e1 /lib/api/labels.rb
parent892371bc22813abe855f563bf4f0ee355fe067ab (diff)
downloadgitlab-ce-998cd3cb63d56a0058c8e519d7c20e3d6e540899.tar.gz
Improve error reporting on users API
* users (#6878, #3526, #4209): Validation error messages are now exposed through 400 responses, 409 response are sent in case of duplicate email or username * MRs (#5335): 409 responses are sent in case of duplicate merge request (source/target branches), 422 responses are sent when submiting MR fo/from unrelated forks * issues * labels * projects
Diffstat (limited to 'lib/api/labels.rb')
-rw-r--r--lib/api/labels.rb31
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index 2fdf53ffec2..78ca58ad0d1 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -30,16 +30,14 @@ module API
attrs = attributes_for_keys [:name, :color]
label = user_project.find_label(attrs[:name])
- if label
- return render_api_error!('Label already exists', 409)
- end
+ conflict!('Label already exists') if label
label = user_project.labels.create(attrs)
if label.valid?
present label, with: Entities::Label
else
- render_api_error!(label.errors.full_messages.join(', '), 400)
+ render_validation_error!(label)
end
end
@@ -56,9 +54,7 @@ module API
required_attributes! [:name]
label = user_project.find_label(params[:name])
- if !label
- return render_api_error!('Label not found', 404)
- end
+ not_found!('Label') unless label
label.destroy
end
@@ -66,10 +62,11 @@ module API
# Updates an existing label. At least one optional parameter is required.
#
# Parameters:
- # id (required) - The ID of a project
- # name (optional) - The name of the label to be deleted
- # color (optional) - Color of the label given in 6-digit hex
- # notation with leading '#' sign (e.g. #FFAABB)
+ # id (required) - The ID of a project
+ # name (required) - The name of the label to be deleted
+ # new_name (optional) - The new name of the label
+ # color (optional) - Color of the label given in 6-digit hex
+ # notation with leading '#' sign (e.g. #FFAABB)
# Example Request:
# PUT /projects/:id/labels
put ':id/labels' do
@@ -77,16 +74,14 @@ module API
required_attributes! [:name]
label = user_project.find_label(params[:name])
- if !label
- return render_api_error!('Label not found', 404)
- end
+ not_found!('Label not found') unless label
attrs = attributes_for_keys [:new_name, :color]
if attrs.empty?
- return render_api_error!('Required parameters "name" or "color" ' \
- 'missing',
- 400)
+ render_api_error!('Required parameters "new_name" or "color" ' \
+ 'missing',
+ 400)
end
# Rename new name to the actual label attribute name
@@ -95,7 +90,7 @@ module API
if label.update(attrs)
present label, with: Entities::Label
else
- render_api_error!(label.errors.full_messages.join(', '), 400)
+ render_validation_error!(label)
end
end
end