Commit 564df8c5 authored by allison.browne's avatar allison.browne

Add response based on sentry client error raised

Add an error response for the ProjectTrackingSettingsService
based on the new Sentry::Client error that is raised.
parent 2f17fdb3
......@@ -7,6 +7,7 @@ module ErrorTracking
SENTRY_API_ERROR_TYPE_MISSING_KEYS = 'missing_keys_in_sentry_response'
SENTRY_API_ERROR_TYPE_NON_20X_RESPONSE = 'non_20x_response_from_sentry'
SENTRY_API_ERROR_INVALID_SIZE = 'invalid_size_of_sentry_response'
API_URL_PATH_REGEXP = %r{
\A
......@@ -96,6 +97,8 @@ module ErrorTracking
{ error: e.message, error_type: SENTRY_API_ERROR_TYPE_NON_20X_RESPONSE }
rescue Sentry::Client::MissingKeysError => e
{ error: e.message, error_type: SENTRY_API_ERROR_TYPE_MISSING_KEYS }
rescue Sentry::Client::ResponseInvalidSizeError => e
{ error: e.message, error_type: SENTRY_API_ERROR_INVALID_SIZE }
end
# http://HOST/api/0/projects/ORG/PROJECT
......
......@@ -4,7 +4,7 @@ module Sentry
class Client
Error = Class.new(StandardError)
MissingKeysError = Class.new(StandardError)
ResponseTooBigError = Class.new(StandardError)
ResponseInvalidSizeError = Class.new(StandardError)
attr_accessor :url, :token
......@@ -36,7 +36,7 @@ module Sentry
def check_valid_size(issues)
return if valid_size?(issues)
raise Client::ResponseTooBigError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."
raise Client::ResponseInvalidSizeError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."
end
def valid_size?(issues)
......
......@@ -208,6 +208,28 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
expect(sentry_client).to have_received(:list_issues)
end
end
context 'when sentry client raises Sentry::Client::ResponseInvalidSizeError' do
let(:sentry_client) { spy(:sentry_client) }
let(:error_msg) {"Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."}
before do
synchronous_reactive_cache(subject)
allow(subject).to receive(:sentry_client).and_return(sentry_client)
allow(sentry_client).to receive(:list_issues).with(opts)
.and_raise(Sentry::Client::ResponseInvalidSizeError, error_msg)
end
it 'returns error' do
expect(result).to eq(
error: error_msg,
error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_INVALID_SIZE
)
expect(subject).to have_received(:sentry_client)
expect(sentry_client).to have_received(:list_issues)
end
end
end
describe '#list_sentry_projects' do
......
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