Skip to content

Commit

Permalink
fix: panic on resource tenant project error handling (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 authored Nov 28, 2024
1 parent df9187a commit 7432680
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions octopusdeploy_framework/resource_tenant_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package octopusdeploy_framework

import (
"context"
"errors"
"fmt"
internalErrors "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"net/http"
"strings"

Expand Down Expand Up @@ -90,11 +92,10 @@ func (t *tenantProjectResource) Read(ctx context.Context, req resource.ReadReque

tenant, err := tenants.GetByID(t.Client, spaceID, tenantID)
if err != nil {
apiError := err.(*core.APIError)
if apiError.StatusCode != http.StatusNotFound {
if err := internalErrors.ProcessApiErrorV2(ctx, resp, data, err, "tenant"); err != nil {
resp.Diagnostics.AddError("unable to load tenant", err.Error())
return
}
return
}

data.EnvironmentIDs = util.FlattenStringList(tenant.ProjectEnvironments[projectID])
Expand Down Expand Up @@ -162,10 +163,12 @@ func (t *tenantProjectResource) Delete(ctx context.Context, req resource.DeleteR

tenant, err := tenants.GetByID(t.Client, spaceId, data.TenantID.ValueString())
if err != nil {
apiError := err.(*core.APIError)
if apiError.StatusCode == http.StatusNotFound {
tflog.Info(ctx, fmt.Sprintf("tenant (%s) no longer exists", data.TenantID.ValueString()))
return
var apiError *core.APIError
if errors.As(err, &apiError) {
if apiError.StatusCode == http.StatusNotFound {
tflog.Info(ctx, fmt.Sprintf("tenant (%s) no longer exists", data.TenantID.ValueString()))
return
}
} else {
resp.Diagnostics.AddError("cannot load tenant", err.Error())
return
Expand Down

0 comments on commit 7432680

Please sign in to comment.