Commit 92106de0 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'bw-jira-issue-controller-exceptions' into 'master'

Handle Jira service exceptions a little better in Jira Issue Controller

See merge request gitlab-org/gitlab!36651
parents fbc32fad 29035d83
...@@ -14,13 +14,14 @@ module Projects ...@@ -14,13 +14,14 @@ module Projects
push_frontend_feature_flag(:jira_integration, project) push_frontend_feature_flag(:jira_integration, project)
end end
rescue_from ::Projects::Integrations::Jira::IssuesFinder::IntegrationError, with: :render_integration_error
rescue_from ::Projects::Integrations::Jira::IssuesFinder::RequestError, with: :render_request_error
def index def index
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
render json: issues_json render json: issues_json
rescue Projects::Integrations::Jira::IntegrationError, Projects::Integrations::Jira::RequestError => e
render_bad_request(e)
end end
end end
end end
...@@ -72,8 +73,16 @@ module Projects ...@@ -72,8 +73,16 @@ module Projects
return render_404 unless project.jira_issues_integration_available? && project.external_issue_tracker return render_404 unless project.jira_issues_integration_available? && project.external_issue_tracker
end end
def render_bad_request(error) # Return the informational message to the user
render json: { errors: [error.message] }, status: :bad_request def render_integration_error(exception)
render json: { errors: [exception.message] }, status: :bad_request
end
# Log the specific request error details and return generic message
def render_request_error(exception)
Gitlab::AppLogger.error(exception)
render json: { errors: [_('An error occurred while requesting data from the Jira service')] }, status: :bad_request
end end
end end
end end
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
module Projects module Projects
module Integrations module Integrations
module Jira module Jira
class IssuesFinder
IntegrationError = Class.new(StandardError) IntegrationError = Class.new(StandardError)
RequestError = Class.new(StandardError) RequestError = Class.new(StandardError)
class IssuesFinder
attr_reader :issues, :total_count, :per_page attr_reader :issues, :total_count, :per_page
class << self class << self
......
...@@ -70,7 +70,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -70,7 +70,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
it 'renders bad request for IntegrationError' do it 'renders bad request for IntegrationError' do
expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute) expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute)
.and_raise(Projects::Integrations::Jira::IntegrationError, 'Integration error') .and_raise(Projects::Integrations::Jira::IssuesFinder::IntegrationError, 'Integration error')
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
...@@ -80,12 +80,12 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do ...@@ -80,12 +80,12 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
it 'renders bad request for RequestError' do it 'renders bad request for RequestError' do
expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute) expect_any_instance_of(Projects::Integrations::Jira::IssuesFinder).to receive(:execute)
.and_raise(Projects::Integrations::Jira::RequestError, 'Request error') .and_raise(Projects::Integrations::Jira::IssuesFinder::RequestError, 'Request error')
get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json get :index, params: { namespace_id: project.namespace, project_id: project }, format: :json
expect(response).to have_gitlab_http_status(:bad_request) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['errors']).to eq ['Request error'] expect(json_response['errors']).to eq ['An error occurred while requesting data from the Jira service']
end end
it 'sets pagination headers' do it 'sets pagination headers' do
......
...@@ -17,7 +17,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do ...@@ -17,7 +17,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
context 'when jira service integration does not have project_key' do context 'when jira service integration does not have project_key' do
it 'raises error' do it 'raises error' do
expect { subject }.to raise_error(Projects::Integrations::Jira::IntegrationError, 'Jira project key is not configured') expect { subject }.to raise_error(Projects::Integrations::Jira::IssuesFinder::IntegrationError, 'Jira project key is not configured')
end end
end end
...@@ -27,7 +27,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do ...@@ -27,7 +27,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
end end
it 'raises error' do it 'raises error' do
expect { subject }.to raise_error(Projects::Integrations::Jira::IntegrationError, 'Jira service not configured.') expect { subject }.to raise_error(Projects::Integrations::Jira::IssuesFinder::IntegrationError, 'Jira service not configured.')
end end
end end
...@@ -48,7 +48,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do ...@@ -48,7 +48,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
end end
it 'raises error', :aggregate_failures do it 'raises error', :aggregate_failures do
expect { subject }.to raise_error(Projects::Integrations::Jira::RequestError) expect { subject }.to raise_error(Projects::Integrations::Jira::IssuesFinder::RequestError)
end end
end end
......
...@@ -2663,6 +2663,9 @@ msgstr "" ...@@ -2663,6 +2663,9 @@ msgstr ""
msgid "An error occurred while reordering issues." msgid "An error occurred while reordering issues."
msgstr "" msgstr ""
msgid "An error occurred while requesting data from the Jira service"
msgstr ""
msgid "An error occurred while retrieving calendar activity" msgid "An error occurred while retrieving calendar activity"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment