diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-02-21 14:19:51 +0300 |
---|---|---|
committer | Kamil TrzciĆski <ayufan@ayufan.eu> | 2019-02-21 14:19:51 +0300 |
commit | 536463295c2598505135bc61570ea66e1bad6496 (patch) | |
tree | 4bb61e295d682140d3c0cf8d9c3923e49e9e8e2b /spec | |
parent | 56b82db63a91695a1dec1b7cbf39636bb01ad3df (diff) |
Catch exception in calculate reactive cache
Return the exception as an error.
Diffstat (limited to 'spec')
4 files changed, 44 insertions, 6 deletions
diff --git a/spec/lib/sentry/client_spec.rb b/spec/lib/sentry/client_spec.rb index 6fbf60a6222..88e7e2e5ebb 100644 --- a/spec/lib/sentry/client_spec.rb +++ b/spec/lib/sentry/client_spec.rb @@ -36,7 +36,7 @@ describe Sentry::Client do end it 'does not follow redirects' do - expect { subject }.to raise_exception(Sentry::Client::Error, 'Sentry response error: 302') + expect { subject }.to raise_exception(Sentry::Client::Error, 'Sentry response status code: 302') expect(redirect_req_stub).to have_been_requested expect(redirected_req_stub).not_to have_been_requested end diff --git a/spec/models/error_tracking/project_error_tracking_setting_spec.rb b/spec/models/error_tracking/project_error_tracking_setting_spec.rb index d30228b863c..076ccc96041 100644 --- a/spec/models/error_tracking/project_error_tracking_setting_spec.rb +++ b/spec/models/error_tracking/project_error_tracking_setting_spec.rb @@ -145,6 +145,24 @@ describe ErrorTracking::ProjectErrorTrackingSetting do expect(result).to be_nil end end + + context 'when sentry client raises exception' do + let(:sentry_client) { spy(:sentry_client) } + + 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::Error, 'error message') + end + + it 'returns error' do + expect(result).to eq(error: 'error message') + expect(subject).to have_received(:sentry_client) + expect(sentry_client).to have_received(:list_issues) + end + end end describe '#list_sentry_projects' do diff --git a/spec/services/error_tracking/list_issues_service_spec.rb b/spec/services/error_tracking/list_issues_service_spec.rb index d9dab1d705c..9d4fc62f923 100644 --- a/spec/services/error_tracking/list_issues_service_spec.rb +++ b/spec/services/error_tracking/list_issues_service_spec.rb @@ -45,7 +45,23 @@ describe ErrorTracking::ListIssuesService do it 'result is not ready' do expect(result).to eq( - status: :error, http_status: :no_content, message: 'not ready') + status: :error, http_status: :no_content, message: 'Not ready. Try again later') + end + end + + context 'when list_sentry_issues returns error' do + before do + allow(error_tracking_setting) + .to receive(:list_sentry_issues) + .and_return(error: 'Sentry response status code: 401') + end + + it 'returns the error' do + expect(result).to eq( + status: :error, + http_status: :bad_request, + message: 'Sentry response status code: 401' + ) end end end @@ -58,7 +74,11 @@ describe ErrorTracking::ListIssuesService do it 'returns error' do result = subject.execute - expect(result).to include(status: :error, message: 'access denied') + expect(result).to include( + status: :error, + message: 'Access denied', + http_status: :unauthorized + ) end end @@ -70,7 +90,7 @@ describe ErrorTracking::ListIssuesService do it 'raises error' do result = subject.execute - expect(result).to include(status: :error, message: 'not enabled') + expect(result).to include(status: :error, message: 'Error Tracking is not enabled') end end end diff --git a/spec/services/error_tracking/list_projects_service_spec.rb b/spec/services/error_tracking/list_projects_service_spec.rb index ee9c59e3f65..9f25a633deb 100644 --- a/spec/services/error_tracking/list_projects_service_spec.rb +++ b/spec/services/error_tracking/list_projects_service_spec.rb @@ -53,11 +53,11 @@ describe ErrorTracking::ListProjectsService do context 'sentry client raises exception' do before do expect(error_tracking_setting).to receive(:list_sentry_projects) - .and_raise(Sentry::Client::Error, 'Sentry response error: 500') + .and_raise(Sentry::Client::Error, 'Sentry response status code: 500') end it 'returns error response' do - expect(result[:message]).to eq('Sentry response error: 500') + expect(result[:message]).to eq('Sentry response status code: 500') expect(result[:http_status]).to eq(:bad_request) end end |