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
@@ -36,17 +36,15 @@ func TestAuthenticationMulti(t *testing.T) {
|
||||
defer c2.Shutdown()
|
||||
|
||||
auth := authmethods.NewClient(c1.Client())
|
||||
token1Result, apiErr, err := auth.Authenticate(c1.Context(), amId, map[string]interface{}{"login_name": user, "password": password})
|
||||
token1Result, err := auth.Authenticate(c1.Context(), amId, map[string]interface{}{"login_name": user, "password": password})
|
||||
require.Nil(err)
|
||||
require.Nil(apiErr)
|
||||
token1 := token1Result.Item
|
||||
require.NotNil(token1)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
auth = authmethods.NewClient(c2.Client())
|
||||
token2Result, apiErr, err := auth.Authenticate(c2.Context(), amId, map[string]interface{}{"login_name": user, "password": password})
|
||||
token2Result, err := auth.Authenticate(c2.Context(), amId, map[string]interface{}{"login_name": user, "password": password})
|
||||
require.Nil(err)
|
||||
require.Nil(apiErr)
|
||||
token2 := token2Result.Item
|
||||
require.NotNil(token2)
|
||||
|
||||
@@ -56,13 +54,11 @@ func TestAuthenticationMulti(t *testing.T) {
|
||||
c2.Client().SetToken(token1.Token) // Same token, as it should work on both
|
||||
|
||||
// Create a project, read from the other
|
||||
org, apiErr, err := scopes.NewClient(c1.Client()).Create(c1.Context(), scope.Global.String())
|
||||
org, err := scopes.NewClient(c1.Client()).Create(c1.Context(), scope.Global.String())
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(org.Item)
|
||||
|
||||
proj, apiErr, err := scopes.NewClient(c2.Client()).Read(c2.Context(), org.Item.Id)
|
||||
proj, err := scopes.NewClient(c2.Client()).Read(c2.Context(), org.Item.Id)
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr)
|
||||
require.NotNil(proj.Item)
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping"
|
||||
"github.com/hashicorp/vault/sdk/helper/base62"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -119,7 +118,7 @@ func (tc *TestController) Token() *authtokens.AuthToken {
|
||||
tc.t.Error("no default auth method ID configured")
|
||||
return nil
|
||||
}
|
||||
token, apiErr, err := authmethods.NewClient(tc.Client()).Authenticate(
|
||||
token, err := authmethods.NewClient(tc.Client()).Authenticate(
|
||||
tc.Context(),
|
||||
tc.b.DevAuthMethodId,
|
||||
map[string]interface{}{
|
||||
@@ -131,10 +130,6 @@ func (tc *TestController) Token() *authtokens.AuthToken {
|
||||
tc.t.Error(fmt.Errorf("error logging in: %w", err))
|
||||
return nil
|
||||
}
|
||||
if apiErr != nil {
|
||||
tc.t.Error(fmt.Errorf("api err from logging in: %s", pretty.Sprint(apiErr)))
|
||||
return nil
|
||||
}
|
||||
return token.Item
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user