fix: improve error message for invalid provider credentials (#290)
This commit is contained in:
1 parent
807db1bef1
commit
1882beff3c
2 files changed
+16
No files matched your search
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user