pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.07k stars 473 forks source link

Print response body when any error response received during any interaction with the Pact Broker #1092

Open bethesque opened 4 years ago

bethesque commented 4 years ago

If there's a single/small number of points to put this code so that it worked for all calls, that would be great. One can dream...

If there is not, there are two main use cases that crop up frequently that it would be great to cover.

Print the body when there is a 401 response received from Pactflow. There is text in the error response that helps users with incorrectly configured credentials to fix their configuration (eg. a lot of people try to connect using basic auth instead of their API token. The response body indicates this.) The most common place this happens is during pact publication, because that's the first thing people try to do.

The other main use case is the error response received when publishing verification results. It's possible this output was added in a later version of the code, but people are still using old versions, so if this is already added, then ignore this bit!

Hazz223 commented 4 years ago

Hi, I've been looking into this error, and I think I know how to change to code somewhat to enable this. However, I've been testing PactFlow with the PUT endpoint for publishing pacts, and found that it doesn't seem to return a body, only a status code of 401. I've tried it with the Read only token, and an invalid token. Should there be a body? I wonder if I'm missing something obvious. If i am, sorry about that!

Also, I've noticed in the Pact JVM Docs that there isn't a reference to PactFlow, and wondered if it was worth also linking to the PactFlow docs here too? Just a suggestion.

Thanks!

bethesque commented 4 years ago

Try using a username and password instead of a bearer token, and you'll get a response body. On the weekend I did a change to add an error message for general 401s - I'll release it today.

bethesque commented 4 years ago

And yes, we should put in a link to pactflow. This is the link we'd want https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token

Hazz223 commented 4 years ago

Ah awesome! I'll get some time this weekend to try and integrate it / raise the pull requests.

Javalencanta commented 3 years ago

hi