summaryrefslogtreecommitdiff
path: root/lib/api/helpers.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/helpers.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/helpers.rb')
-rw-r--r--lib/api/helpers.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 6af0f6d1b25..3a619169eca 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -155,7 +155,17 @@ module API
end
def not_allowed!
- render_api_error!('Method Not Allowed', 405)
+ render_api_error!('405 Method Not Allowed', 405)
+ end
+
+ def conflict!(message = nil)
+ render_api_error!(message || '409 Conflict', 409)
+ end
+
+ def render_validation_error!(model)
+ unless model.valid?
+ render_api_error!(model.errors.messages || '400 Bad Request', 400)
+ end
end
def render_api_error!(message, status)