fix: improve error message for invalid provider credentials (#290)

This commit is contained in:
Damian Debkowski authored and GitHub committed 2022-10-17 11:13:45 -07:00
1 parent 807db1bef1
commit 1882beff3c
2 files changed
+16

No files matched your search

+6
View File
@@ -9,6 +9,12 @@ Canonical reference for changes, improvements, and bugfixes for the Boundary Ter
* Add support for setting mapping overrides for vault credential libraries
([PR](https://github.com/hashicorp/terraform-provider-boundary/pull/287)).
### Bug Fixes
* Improve error message when authenticating to boundary.
([PR](https://github.com/hashicorp/terraform-provider-boundary/pull/290)).
## 1.1.1 (October 12, 2022)
### Bug Fixes
+10
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"github.com/hashicorp/boundary/api"
@@ -176,6 +177,15 @@ func providerAuthenticate(ctx context.Context, d *schema.ResourceData, md *metaD
at, err := am.Authenticate(ctx, authMethodId.(string), "login", credentials)
if err != nil {
if apiErr := api.AsServerError(err); apiErr != nil {
statusCode := apiErr.Response().StatusCode()
if statusCode == http.StatusNotFound {
return fmt.Errorf("unknown auth_method_id: %s", err.Error())
}
if statusCode == http.StatusUnauthorized {
return fmt.Errorf("invalid login name or password: %s", err.Error())
}
}
return err
}
md.client.SetToken(at.Attributes["token"].(string))