Skip to content

Commit

Permalink
PLT-701-2: Enhanced the error message for macro duplications (#421)
Browse files Browse the repository at this point in the history
* PLT-701-2: Enhanced the error message for macro duplications

* remove commented line

* fixed vet issue
  • Loading branch information
SivaanandM authored Feb 6, 2024
1 parent 8b523cb commit bd9f8be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion spectrocloud/resource_macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit bd9f8be

Please sign in to comment.