Commit da503d12 authored by Catalin Irimie's avatar Catalin Irimie

Log Bitbucket Unauthorized exceptions

When redirecting to Bitbucket in the import controller because
of an exception we're rescuing from, we should also log it.
parent 7ea0bc4e
...@@ -116,7 +116,9 @@ class Import::BitbucketController < Import::BaseController ...@@ -116,7 +116,9 @@ class Import::BitbucketController < Import::BaseController
redirect_to oauth_client.auth_code.authorize_url(redirect_uri: users_import_bitbucket_callback_url) redirect_to oauth_client.auth_code.authorize_url(redirect_uri: users_import_bitbucket_callback_url)
end end
def bitbucket_unauthorized def bitbucket_unauthorized(exception)
log_exception(exception)
go_to_bitbucket_for_permissions go_to_bitbucket_for_permissions
end end
......
...@@ -252,6 +252,30 @@ RSpec.describe Import::BitbucketController do ...@@ -252,6 +252,30 @@ RSpec.describe Import::BitbucketController do
end end
end end
end end
context "when exceptions occur" do
shared_examples "handles exceptions" do
it "logs an exception" do
expect(Bitbucket::Client).to receive(:new).and_raise(error)
expect(controller).to receive(:log_exception)
post :create, format: :json
end
end
context "for OAuth2 errors" do
let(:fake_response) { double('Faraday::Response', headers: {}, body: '', status: 403) }
let(:error) { OAuth2::Error.new(OAuth2::Response.new(fake_response)) }
it_behaves_like "handles exceptions"
end
context "for Bitbucket errors" do
let(:error) { Bitbucket::Error::Unauthorized.new("error") }
it_behaves_like "handles exceptions"
end
end
end end
context 'user has chosen an existing nested namespace and name for the project' do context 'user has chosen an existing nested namespace and name for the project' 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