From bd9f8be3416b23473252e3a516b0974bcdf6c9f4 Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Tue, 6 Feb 2024 10:59:19 +0530 Subject: [PATCH] PLT-701-2: Enhanced the error message for macro duplications (#421) * PLT-701-2: Enhanced the error message for macro duplications * remove commented line * fixed vet issue --- spectrocloud/resource_macros.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spectrocloud/resource_macros.go b/spectrocloud/resource_macros.go index 72273cdc..a0f60a31 100644 --- a/spectrocloud/resource_macros.go +++ b/spectrocloud/resource_macros.go @@ -2,8 +2,10 @@ package spectrocloud import ( "context" + "errors" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/spectrocloud/hapi/apiutil/transport" "github.com/spectrocloud/hapi/models" "github.com/spectrocloud/palette-sdk-go/client" "time" @@ -118,10 +120,17 @@ func resourceMacrosUpdate(ctx context.Context, d *schema.ResourceData, m interfa existMacros, _ := c.GetExistMacros(oldMacros.(map[string]interface{}), uid) err = c.UpdateMacros(uid, mergeExistingMacros(d, existMacros)) if err != nil { + var e *transport.TransportError + if errors.As(err, &e) && e.HttpCode == 422 { + if err := d.Set("macros", oldMacros); err != nil { + return diag.FromErr(err) + } + e.Payload.Message = e.Payload.Message + "\n Kindly verify if any of the specified macro names already exist in the system." + return diag.FromErr(e) + } return diag.FromErr(err) } } - return diags }