diff options
author | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-03-05 23:43:05 +0100 |
---|---|---|
committer | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-03-05 23:43:05 +0100 |
commit | b5ef6d226864d3ea132d2c6e97b74b51f2b64a6f (patch) | |
tree | 5f78f405044dc54da75ec25a47bc9712a70ab162 | |
parent | cce35b6d057611d792bdc70022bd7264798527a7 (diff) | |
download | gitlab-ce-b5ef6d226864d3ea132d2c6e97b74b51f2b64a6f.tar.gz |
API: refactored and simplified error handling in merge requests API
-rw-r--r-- | lib/api/merge_requests.rb | 23 | ||||
-rw-r--r-- | lib/api/projects.rb | 3 |
2 files changed, 8 insertions, 18 deletions
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 7e4ec7e803c..5adf57b36c5 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -4,21 +4,12 @@ module Gitlab before { authenticate! } resource :projects do - helpers do - # If an error occurred this helper method provides an appropriate status code - # - # Parameters: - # merge_request_errors (required) - The errors collection of MR - # - def handle_merge_request_error(merge_request_errors) - if merge_request_errors[:target_branch].any? - bad_request!(:target_branch) - elsif merge_request_errors[:source_branch].any? - bad_request!(:source_branch) - elsif merge_request_errors[:base].any? - error!(merge_request_errors[:base], 422) + def handle_merge_request_errors!(errors) + if errors[:project_access].any? + error!(errors[:project_access], 422) end + not_found! end end @@ -78,8 +69,7 @@ module Gitlab merge_request.reload_code present merge_request, with: Entities::MergeRequest else - handle_merge_request_error(merge_request.errors) - not_found! + handle_merge_request_errors! merge_request.errors end end @@ -107,8 +97,7 @@ module Gitlab merge_request.mark_as_unchecked present merge_request, with: Entities::MergeRequest else - handle_merge_request_error(merge_request.errors) - not_found! + handle_merge_request_errors! merge_request.errors end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index cf48f88bec9..b8efef318d3 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -233,7 +233,7 @@ module Gitlab end end - # Delete project hook + # Deletes project hook. This is an idempotent function. # # Parameters: # id (required) - The ID of a project @@ -248,6 +248,7 @@ module Gitlab @hook = ProjectHook.find(params[:hook_id]) @hook.destroy rescue + # ProjectHook can raise Error if hook_id not found end end |