Skip to content

Commit

Permalink
Ensure create/update funcs return early if errored
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhung committed Dec 18, 2024
1 parent 6784387 commit da70c73
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/project/resource/resource_project_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package project
import (
"context"
"fmt"
"net/http"
"regexp"
"strings"

Expand Down Expand Up @@ -114,9 +113,11 @@ func (r *ProjectEnvironmentResource) Create(ctx context.Context, req resource.Cr
Post(ProjectEnvironmentUrl)
if err != nil {
utilfw.UnableToCreateResourceError(resp, err.Error())
return
}
if response.IsError() {
utilfw.UnableToCreateResourceError(resp, projectError.String())
return
}

plan.ID = types.StringValue(environment.Name)
Expand Down Expand Up @@ -148,10 +149,6 @@ func (r *ProjectEnvironmentResource) Read(ctx context.Context, req resource.Read
utilfw.UnableToRefreshResourceError(resp, err.Error())
return
}
if response.StatusCode() == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
if response.IsError() {
utilfw.UnableToRefreshResourceError(resp, projectError.String())
return
Expand Down Expand Up @@ -211,9 +208,11 @@ func (r *ProjectEnvironmentResource) Update(ctx context.Context, req resource.Up
Post(ProjectEnvironmentUrl + "/{environmentName}/rename")
if err != nil {
utilfw.UnableToUpdateResourceError(resp, err.Error())
return
}
if response.IsError() {
utilfw.UnableToUpdateResourceError(resp, projectError.String())
return
}

plan.ID = types.StringValue(environmentUpdate.NewName)
Expand Down

0 comments on commit da70c73

Please sign in to comment.