DrFaust92 / terraform-provider-bitbucket

Terraform Bitbucket Cloud provider.
https://registry.terraform.io/providers/drfaust92/bitbucket
Mozilla Public License 2.0
38 stars 30 forks source link

fix(branch-restriction): handle http errors #125

Closed Nkmol closed 1 year ago

Nkmol commented 1 year ago

This PR makes sure that the HTTP errors (GenericSwaggerError) is actually handled whenever it is returned.

We differentiate between normal error objects and GenericSwaggerError by testing a type cast. I tried to wrap this logic in a helper function we can easily use throughout any of the resources.


Example error output:

REST Error

bitbucket_branch_restriction.development: Creating...
╷
│ Error: 409 Conflict: a branch restriction with that kind (force) and branch type (development) already exists (id=34493232)
│ 
│   with bitbucket_branch_restriction.development,
│   on example.tf line 13, in resource "bitbucket_branch_restriction" "development":
│   13: resource "bitbucket_branch_restriction" "development" {
│ 
╵

Auth Error

bitbucket_branch_restriction.development: Creating...
╷
│ Error: Login failed due to incorrect login credentials or method.
│ For information on authentication methods for Bitbucket Cloud APIs, visit:
│     https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication
│ If you are unsure of which login details or login method to use, visit:
│     https://support.atlassian.com/bitbucket-cloud/docs/log-into-or-connect-to-bitbucket-cloud/
│ 
│ 
│   with bitbucket_branch_restriction.development,
│   on example.tf line 13, in resource "bitbucket_branch_restriction" "development":
│   13: resource "bitbucket_branch_restriction" "development" {
│ 

Relates to #93