Skip to content

Commit

Permalink
feat(cli): print any response body from the Pact Broker when authenti…
Browse files Browse the repository at this point in the history
…cation fails
  • Loading branch information
bethesque committed Feb 17, 2020
1 parent 373e4b0 commit 116f0d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/pact_broker/client/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/pact_broker/client/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/client/base_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ module Client
let(:password) { 'pact_repo_password'}
let(:token) { '123456789' }
let(:client_options) do
{
{
basic_auth: {
username: username,
password: password
},
token: token
}
end

context 'with basic url' do
it 'sets the base url' do
base_client = BaseClient.new(base_url: base_url)
Expand Down

0 comments on commit 116f0d9

Please sign in to comment.