Skip to content

Commit

Permalink
use IgnoreErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushrangwala committed Feb 23, 2024
1 parent 6695ce3 commit 010c786
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/resources/metal/vlans/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"errors"
"fmt"
"net/http"

equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
"github.com/equinix/terraform-provider-equinix/internal/framework"

Expand Down Expand Up @@ -149,10 +147,10 @@ func (r *Resource) Delete(ctx context.Context, request resource.DeleteRequest, r
&packngo.GetOptions{Includes: []string{"instances", "meta_gateway"}},
)
if err != nil {
if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusNotFound {
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
response.Diagnostics.AddWarning(
"Equinix Metal Vlan not found during delete",
err.Error(),
equinix_errors.FriendlyError(err).Error(),
)
return
}
Expand All @@ -167,7 +165,7 @@ func (r *Resource) Delete(ctx context.Context, request resource.DeleteRequest, r
for _, v := range port.AttachedVirtualNetworks {
if v.ID == vlan.ID {
_, resp, err = client.Ports.Unassign(port.ID, vlan.ID)
if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusNotFound {
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
response.Diagnostics.AddError("Error unassign port with Vlan",
equinix_errors.FriendlyError(err).Error())
return
Expand All @@ -177,8 +175,7 @@ func (r *Resource) Delete(ctx context.Context, request resource.DeleteRequest, r
}
}

resp, err = client.ProjectVirtualNetworks.Delete(vlan.ID)
if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusNotFound {
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(client.ProjectVirtualNetworks.Delete(vlan.ID)) != nil {
response.Diagnostics.AddError("Error deleting Vlan",
equinix_errors.FriendlyError(err).Error())
return
Expand Down

0 comments on commit 010c786

Please sign in to comment.