Skip to content

Commit

Permalink
[ignore] fixed utils.go
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahammughal committed Aug 8, 2024
1 parent 3d94130 commit c6a20b0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/provider/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

func ContainsString(strings []string, matchString string) bool {
Expand Down Expand Up @@ -75,7 +76,18 @@ func DoRestRequestEscapeHtml(ctx context.Context, diags *diag.Diagnostics, aciCl

if restResponse != nil && cont.Data() != nil && restResponse.StatusCode != 200 {
errCode := models.StripQuotes(models.StripSquareBrackets(cont.Search("imdata", "error", "attributes", "code").String()))
if errCode != "103" && errCode != "107" && errCode != "120" {
errText := models.StripQuotes(models.StripSquareBrackets(cont.Search("imdata", "error", "attributes", "text").String()))
// Ignore errors of type "Cannot create object", "Cannot delete object", "Request in progress" and error text containing "can not be deleted." when the error code is 120
if errCode == "103" || errCode == "107" || errCode == "202" || (errCode == "120" && strings.HasSuffix(errText, "can not be deleted.")) {
tflog.Debug(ctx, fmt.Sprintf("Exiting from error: Code: %s, Message: %s", errCode, errText))
return nil
} else if (errText == "" && errCode == "403") || errCode == "401" {
diags.AddError(
"Unable to authenticate. Please check your credentials",
fmt.Sprintf("Response Status Code: %d, Error Code: %s, Error Message: %s.", restResponse.StatusCode, errCode, errText),
)
return nil
} else {
diags.AddError(
fmt.Sprintf("The %s rest request failed", strings.ToLower(method)),
fmt.Sprintf("Response Status Code: %d, Error Code: %s, Error Message: %s.", restResponse.StatusCode, errCode, errText),
Expand Down

0 comments on commit c6a20b0

Please sign in to comment.