SDK error revamp (#432)
SDK methods now return 1 error. To differentiate between Client errors and Server errors I've also implemented the AsServerError function which returns an *api.Error if it is an error originating from the remote server or nil otherwise.
This commit is contained in:
1 parent
94f9d952be
commit
fd0da998e8
53 files changed
+1512
-1635
No files matched your search
@@ -8,10 +8,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/authmethods"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/vault/sdk/helper/password"
|
||||
"github.com/kr/pretty"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/mitchellh/go-wordwrap"
|
||||
"github.com/posener/complete"
|
||||
@@ -121,19 +121,19 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
// note: Authenticate() calls SetToken() under the hood to set the
|
||||
// auth bearer on the client so we do not need to do anything with the
|
||||
// returned token after this call, so we ignore it
|
||||
result, apiErr, err := authmethods.NewClient(client).Authenticate(c.Context, c.flagAuthMethodId,
|
||||
result, err := authmethods.NewClient(client).Authenticate(c.Context, c.flagAuthMethodId,
|
||||
map[string]interface{}{
|
||||
"login_name": c.flagLoginName,
|
||||
"password": c.flagPassword,
|
||||
})
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing authentication: %s", err.Error()))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to perform authentication: %s", err.Error()))
|
||||
return 2
|
||||
}
|
||||
if apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing authentication: %s", pretty.Sprint(apiErr)))
|
||||
return 1
|
||||
}
|
||||
|
||||
token := result.Item
|
||||
switch base.Format(c.UI) {
|
||||
|
||||
Reference in new issue
Block a user