summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-07-31 12:20:06 +0000
committerSean McGivern <sean@gitlab.com>2019-07-31 12:20:06 +0000
commitf10295b2956665d351eb413d380673090cb13b24 (patch)
treeb81d738c5dd2fc1e10cbb13ffcea8bdff17463ec
parentcbceb1ce7e7b6bdd04be58ac0f9ae5e81872e5c1 (diff)
parent8a1fc36e1d3df359c7ab87a5d3b40cf35b2a8604 (diff)
downloadgitlab-ce-f10295b2956665d351eb413d380673090cb13b24.tar.gz
Merge branch 'ajk-handle-gql-errors' into 'master'
Propagate argument errors as execution errors See merge request gitlab-org/gitlab-ce!31249
-rw-r--r--app/controllers/graphql_controller.rb4
-rw-r--r--spec/controllers/graphql_controller_spec.rb21
2 files changed, 25 insertions, 0 deletions
diff --git a/app/controllers/graphql_controller.rb b/app/controllers/graphql_controller.rb
index 9fbbe373b0d..72d40f709e6 100644
--- a/app/controllers/graphql_controller.rb
+++ b/app/controllers/graphql_controller.rb
@@ -30,6 +30,10 @@ class GraphqlController < ApplicationController
render_error(exception.message, status: :unprocessable_entity)
end
+ rescue_from Gitlab::Graphql::Errors::ArgumentError do |exception|
+ render_error(exception.message, status: :unprocessable_entity)
+ end
+
private
def execute_multiplex
diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb
index c19a752b07b..9937bdf4061 100644
--- a/spec/controllers/graphql_controller_spec.rb
+++ b/spec/controllers/graphql_controller_spec.rb
@@ -7,6 +7,27 @@ describe GraphqlController do
stub_feature_flags(graphql: true)
end
+ describe 'ArgumentError' do
+ let(:user) { create(:user) }
+ let(:message) { 'green ideas sleep furiously' }
+
+ before do
+ sign_in(user)
+ end
+
+ it 'handles argument errors' do
+ allow(subject).to receive(:execute) do
+ raise Gitlab::Graphql::Errors::ArgumentError, message
+ end
+
+ post :execute
+
+ expect(json_response).to include(
+ 'errors' => include(a_hash_including('message' => message))
+ )
+ end
+ end
+
describe 'POST #execute' do
context 'when user is logged in' do
let(:user) { create(:user) }