Closed Nkmol closed 5 months ago
This looks useful. I've observed errors can be very opaque so bubbling it up from the bitbucket API seems helpful. https://github.com/DrFaust92/terraform-provider-bitbucket/issues/199
Example when I intentionally make my username (via BITBUCKET_USERNAME) incorrect.
╷
│ Error: Empty Summary: This is always a bug in the provider and should be reported to the provider developers.
│
│ with bitbucket_repository.foobar,
│ on foobar.tf line 1, in resource "bitbucket_repository" "foobar":
│ 1: resource "bitbucket_repository" "foobar" {
This PR makes sure that an authorization error (
401 Unauthorized
) is at least shown to the end user.Bitbucket responses, mainly headers and error codes, seem to have completely changed. For the unauthorized response, the
Content-Type
was changed to"text/plain"
where no HTTP-body is returned any more.Because of this, the client's decoding fails (see https://github.com/DrFaust92/bitbucket-go-client/blob/main/client.go#L387), and the original Bitbucket API error is no longer passed to the Terraform code.
To overcome this issue, I now rely on the raw HTTP Response and always log the original HTTP Code. The main files to review are the tests and the
bitbucket/error.go
file.Authorization error
Other Bitbucket API error
I ran the acceptance tests, but found some issues that also happen on the master branch.
An individual run, for example for the Bitbucket Repository resource, shows an error that is not caused by this PR:
Manual tested a correct apply, authorization error and a Bitbucket API error.