fix: make sure the authorization error is correctly shown to the end user #200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.