diff --git a/lib/pact_broker/client/base_client.rb b/lib/pact_broker/client/base_client.rb index ea12b6db..2df7b8e7 100644 --- a/lib/pact_broker/client/base_client.rb +++ b/lib/pact_broker/client/base_client.rb @@ -70,7 +70,11 @@ def handle_response response elsif response.code == 404 nil elsif response.code == 401 - raise Error.new("Authentication failed") + message = "Authentication failed" + if response.body && response.body.size > 0 + message = message + ": #{response.body}" + end + raise Error.new(message) else error_message = nil begin diff --git a/lib/pact_broker/client/matrix.rb b/lib/pact_broker/client/matrix.rb index e5b3a53f..4e409777 100644 --- a/lib/pact_broker/client/matrix.rb +++ b/lib/pact_broker/client/matrix.rb @@ -20,7 +20,11 @@ def handle_response response if response.success? yield elsif response.code == 401 - raise Error.new("Authentication failed") + message = "Authentication failed" + if response.body && response.body.size > 0 + message = message + ": #{response.body}" + end + raise Error.new(message) elsif response.code == 404 raise Error.new("Matrix resource not found at #{base_url}/matrix. Please upgrade your Broker to the latest version.") else diff --git a/spec/lib/pact_broker/client/base_client_spec.rb b/spec/lib/pact_broker/client/base_client_spec.rb index 1f5b3d82..985e2fc0 100644 --- a/spec/lib/pact_broker/client/base_client_spec.rb +++ b/spec/lib/pact_broker/client/base_client_spec.rb @@ -10,7 +10,7 @@ module Client let(:password) { 'pact_repo_password'} let(:token) { '123456789' } let(:client_options) do - { + { basic_auth: { username: username, password: password @@ -18,7 +18,7 @@ module Client token: token } end - + context 'with basic url' do it 'sets the base url' do base_client = BaseClient.new(base_url: base_url)