Don't return an empty resource if there was an apiErr (#294)
This commit is contained in:
1 parent
b24fc185a7
commit
627a353ccb
11 files changed
+198
-66
No files matched your search
+15
-5
@@ -59,7 +59,9 @@ func (c *HostsClient) Create(ctx context.Context, hostCatalogId string, opt ...O
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Create response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -93,7 +95,9 @@ func (c *HostsClient) Read(ctx context.Context, hostCatalogId string, hostId str
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Read response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -144,7 +148,9 @@ func (c *HostsClient) Update(ctx context.Context, hostCatalogId string, hostId s
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Update response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -181,7 +187,9 @@ func (c *HostsClient) Delete(ctx context.Context, hostCatalogId string, hostId s
|
||||
if err != nil {
|
||||
return false, nil, fmt.Errorf("error decoding Delete response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return false, apiErr, nil
|
||||
}
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -214,6 +222,8 @@ func (c *HostsClient) List(ctx context.Context, hostCatalogId string, opt ...Opt
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding List response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
@@ -59,7 +59,9 @@ func (c *HostCatalogsClient) Create(ctx context.Context, resourceType string, op
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Create response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -89,7 +91,9 @@ func (c *HostCatalogsClient) Read(ctx context.Context, hostCatalogId string, opt
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Read response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -137,7 +141,9 @@ func (c *HostCatalogsClient) Update(ctx context.Context, hostCatalogId string, v
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Update response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -170,7 +176,9 @@ func (c *HostCatalogsClient) Delete(ctx context.Context, hostCatalogId string, o
|
||||
if err != nil {
|
||||
return false, nil, fmt.Errorf("error decoding Delete response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return false, apiErr, nil
|
||||
}
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -199,6 +207,8 @@ func (c *HostCatalogsClient) List(ctx context.Context, opt ...Option) ([]*HostCa
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding List response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
@@ -58,7 +58,9 @@ func (c *HostSetsClient) Create(ctx context.Context, hostCatalogId string, opt .
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Create response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -92,7 +94,9 @@ func (c *HostSetsClient) Read(ctx context.Context, hostCatalogId string, hostSet
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Read response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -143,7 +147,9 @@ func (c *HostSetsClient) Update(ctx context.Context, hostCatalogId string, hostS
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding Update response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -180,7 +186,9 @@ func (c *HostSetsClient) Delete(ctx context.Context, hostCatalogId string, hostS
|
||||
if err != nil {
|
||||
return false, nil, fmt.Errorf("error decoding Delete response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return false, apiErr, nil
|
||||
}
|
||||
return target.Existed, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -213,7 +221,9 @@ func (c *HostSetsClient) List(ctx context.Context, hostCatalogId string, opt ...
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding List response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target.Items, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -268,7 +278,9 @@ func (c *HostSetsClient) AddHosts(ctx context.Context, hostCatalogId string, hos
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding AddHosts response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -326,7 +338,9 @@ func (c *HostSetsClient) SetHosts(ctx context.Context, hostCatalogId string, hos
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding SetHosts response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
|
||||
@@ -381,6 +395,8 @@ func (c *HostSetsClient) RemoveHosts(ctx context.Context, hostCatalogId string,
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("error decoding RemoveHosts response: %w", err)
|
||||
}
|
||||
|
||||
if apiErr != nil {
|
||||
return nil, apiErr, nil
|
||||
}
|
||||
return target, apiErr, nil
|
||||
}
|
||||
Reference in new issue
Block a user