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

@@ -10,7 +10,6 @@ import (
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/boundary/sdk/strutil"
"github.com/kr/pretty"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
@@ -185,24 +184,23 @@ func (c *PasswordCommand) Run(args []string) int {
}
var result api.GenericResult
var apiErr *api.Error
switch c.Func {
case "create":
result, apiErr, err = authmethodClient.Create(c.Context, "password", c.FlagScopeId, opts...)
result, err = authmethodClient.Create(c.Context, "password", c.FlagScopeId, opts...)
case "update":
result, apiErr, err = authmethodClient.Update(c.Context, c.FlagId, version, opts...)
result, err = authmethodClient.Update(c.Context, c.FlagId, version, opts...)
}
plural := "password-type auth-method"
if err != nil {
if api.AsServerError(err) != nil {
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
return 1
}
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
return 2
}
if apiErr != nil {
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, pretty.Sprint(apiErr)))
return 1
}
method := result.GetItem().(*authmethods.AuthMethod)
switch base.Format(c.UI) {