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
push_frontend_feature_flag(:jira_integration, project)
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
respond_to do |format|
format.html
format.json do
render json: issues_json
rescue Projects::Integrations::Jira::IntegrationError, Projects::Integrations::Jira::RequestError => e
render_bad_request(e)
end
end
end
......@@ -72,8 +73,16 @@ module Projects
return render_404 unless project.jira_issues_integration_available? && project.external_issue_tracker
end
def render_bad_request(error)
render json: { errors: [error.message] }, status: :bad_request
# Return the informational message to the user
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
......
......@@ -3,10 +3,10 @@
module Projects
module Integrations
module Jira
IntegrationError = Class.new(StandardError)
RequestError = Class.new(StandardError)
class IssuesFinder
IntegrationError = Class.new(StandardError)
RequestError = Class.new(StandardError)
attr_reader :issues, :total_count, :per_page
class << self
......
......@@ -70,7 +70,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
it 'renders bad request for IntegrationError' do
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
......@@ -80,12 +80,12 @@ RSpec.describe Projects::Integrations::Jira::IssuesController do
it 'renders bad request for RequestError' do
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
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
it 'sets pagination headers' do
......
......@@ -17,7 +17,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
context 'when jira service integration does not have project_key' 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
......@@ -27,7 +27,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
end
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
......@@ -48,7 +48,7 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
end
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
......
......@@ -2663,6 +2663,9 @@ msgstr ""
msgid "An error occurred while reordering issues."
msgstr ""
msgid "An error occurred while requesting data from the Jira service"
msgstr ""
msgid "An error occurred while retrieving calendar activity"
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