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:
Todd Knight authored and GitHub committed 2020-09-24 14:34:58 -07:00
1 parent 94f9d952be
commit fd0da998e8
53 files changed
+1512 -1635

No files matched your search

+6 -6
View File
@@ -21,6 +21,7 @@ import (
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
@@ -28,7 +29,6 @@ import (
"github.com/hashicorp/boundary/internal/proxy"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/kr/pretty"
"github.com/mitchellh/cli"
"github.com/posener/complete"
"go.uber.org/atomic"
@@ -318,15 +318,15 @@ func (c *Command) Run(args []string) (retCode int) {
opts = append(opts, targets.WithHostId(c.flagHostId))
}
sar, apiErr, err := targetClient.Authorize(c.Context, c.flagTargetId, opts...)
sar, err := targetClient.Authorize(c.Context, c.flagTargetId, opts...)
if err != nil {
if api.AsServerError(err) != nil {
c.UI.Error(fmt.Sprintf("Error from controller when performing authorize on a session against target: %s", err.Error()))
return 1
}
c.UI.Error(fmt.Sprintf("Error trying to authorize a session against target: %s", err.Error()))
return 2
}
if apiErr != nil {
c.UI.Error(fmt.Sprintf("Error from controller when performing authorize on a session against target: %s", pretty.Sprint(apiErr)))
return 1
}
sa := sar.GetItem().(*targets.SessionAuthorization)
authzString = sa.AuthorizationToken
}