From cd0aed3d54fc01d0c361a8cf282d2de48297f66a Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 7 Jan 2015 10:46:00 +0100 Subject: Add a message when unable to save an object through api. --- lib/api/commits.rb | 2 +- lib/api/deploy_keys.rb | 2 +- lib/api/groups.rb | 4 ++-- lib/api/issues.rb | 8 ++++---- lib/api/labels.rb | 4 ++-- lib/api/merge_requests.rb | 4 ++-- lib/api/milestones.rb | 4 ++-- lib/api/notes.rb | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 8e528e266bf..0de4e720ffe 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -108,7 +108,7 @@ module API if note.save present note, with: Entities::CommitNote else - render_api_error!("Failed to save note #{note.errors.messages}", 422) + render_api_error!("Failed to save note #{note.errors.messages}", 400) end end end diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb index 06eb7756841..dd4b761feb2 100644 --- a/lib/api/deploy_keys.rb +++ b/lib/api/deploy_keys.rb @@ -58,7 +58,7 @@ module API if key.valid? && user_project.deploy_keys << key present key, with: Entities::SSHKey else - render_validation_error!(key) + render_api_error!("Failed to add key #{key.errors.messages}", 400) end end diff --git a/lib/api/groups.rb b/lib/api/groups.rb index cee51c82ad5..bda60b3b7d5 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -54,7 +54,7 @@ module API if @group.save present @group, with: Entities::Group else - render_api_error!("Failed to save group #{@group.errors.messages}", 422) + render_api_error!("Failed to save group #{@group.errors.messages}", 400) end end @@ -97,7 +97,7 @@ module API if result present group else - render_api_error!("Failed to transfer project #{project.errors.messages}", 422) + render_api_error!("Failed to transfer project #{project.errors.messages}", 400) end end end diff --git a/lib/api/issues.rb b/lib/api/issues.rb index d2828b24c36..01496c39955 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -104,7 +104,7 @@ module API # Validate label names in advance if (errors = validate_label_params(params)).any? - render_api_error!({ labels: errors }, 400) + render_api_error!("Unable to validate label: #{errors}"}, 400) end issue = ::Issues::CreateService.new(user_project, current_user, attrs).execute @@ -118,7 +118,7 @@ module API present issue, with: Entities::Issue else - render_validation_error!(issue) + render_api_error!("Unable to create issue #{issue.errors.messages}", 400) end end @@ -142,7 +142,7 @@ module API # Validate label names in advance if (errors = validate_label_params(params)).any? - render_api_error!({ labels: errors }, 400) + render_api_error!("Unable to validate label: #{errors}"}, 400) end issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue) @@ -158,7 +158,7 @@ module API present issue, with: Entities::Issue else - render_validation_error!(issue) + render_api_error!("Unable to update issue #{issue.errors.messages}", 400) end end diff --git a/lib/api/labels.rb b/lib/api/labels.rb index 78ca58ad0d1..e8ded662253 100644 --- a/lib/api/labels.rb +++ b/lib/api/labels.rb @@ -37,7 +37,7 @@ module API if label.valid? present label, with: Entities::Label else - render_validation_error!(label) + render_api_error!("Unable to create label #{label.errors.messages}", 400) end end @@ -90,7 +90,7 @@ module API if label.update(attrs) present label, with: Entities::Label else - render_validation_error!(label) + render_api_error!("Unable to create label #{label.errors.messages}", 400) end end end diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index a365f1db00f..1a73c4943b8 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -137,7 +137,7 @@ module API # Validate label names in advance if (errors = validate_label_params(params)).any? - render_api_error!({ labels: errors }, 400) + render_api_error!("Unable to validate label: #{errors}"}, 400) end merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, attrs).execute(merge_request) @@ -233,7 +233,7 @@ module API if note.save present note, with: Entities::MRNote else - render_validation_error!(note) + render_api_error!("Failed to save note #{note.errors.messages}", 400) end end end diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 4d79f5a69ae..2ea49359df0 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -48,7 +48,7 @@ module API if milestone.valid? present milestone, with: Entities::Milestone else - not_found!("Milestone #{milestone.errors.messages}") + render_api_error!("Failed to create milestone #{milestone.errors.messages}", 400) end end @@ -72,7 +72,7 @@ module API if milestone.valid? present milestone, with: Entities::Milestone else - not_found!("Milestone #{milestone.errors.messages}") + render_api_error!("Failed to update milestone #{milestone.errors.messages}", 400) end end end diff --git a/lib/api/notes.rb b/lib/api/notes.rb index b04d623c695..3726be7c537 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -93,7 +93,7 @@ module API if @note.valid? present @note, with: Entities::Note else - bad_request!('Invalid note') + render_api_error!("Failed to save note #{note.errors.messages}", 400) end end -- cgit v1.2.1