Skip to content

Commit

Permalink
annotate where and why we convert to ErrorResponse for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Jun 19, 2024
1 parent 83f83fd commit b50e3e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/resources/metal/virtual_circuit/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ func getVCStateWaiter(ctx context.Context, client *metalv1.APIClient, id string,
vc, resp, err := client.InterconnectionsApi.GetVirtualCircuit(ctx, id).Execute()
if err != nil {
if resp != nil {
// The resource delete function uses this waiter and relies
// on it to return an ErrorResponse error so it can treat
// a 404 as success. This conversion is done here for now
// to avoid a larger refactoring.
err = equinix_errors.FriendlyErrorForMetalGo(err, resp)
}
return 0, "", err
Expand Down Expand Up @@ -422,7 +426,7 @@ func resourceMetalVirtualCircuitUpdate(ctx context.Context, d *schema.ResourceDa

if needsUpdate {
if _, _, err := client.InterconnectionsApi.UpdateVirtualCircuit(ctx, d.Id()).VirtualCircuitUpdateInput(ur).Execute(); err != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
return diag.FromErr(err)
}
}
return resourceMetalVirtualCircuitRead(ctx, d, meta)
Expand All @@ -434,10 +438,13 @@ func resourceMetalVirtualCircuitDelete(ctx context.Context, d *schema.ResourceDa
_, resp, err := client.InterconnectionsApi.DeleteVirtualCircuit(ctx, d.Id()).Execute()
if err != nil {
if resp != nil {
// equinix_error.HttpNotFound and similar do not short-circuit
// based on response code, so we have to convert to a FriendlyError
// in order to use existing checks for equinix_errors.IgnoreHttpResponseErrors
err = equinix_errors.FriendlyErrorForMetalGo(err, resp)
}
if equinix_errors.IgnoreHttpResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
return diag.FromErr(err)
}
}

Expand Down

0 comments on commit b50e3e9

Please sign in to comment.