Skip to content

Commit

Permalink
[ignore] Add change to error handling when ndo resturns 404 for templ…
Browse files Browse the repository at this point in the history
…ate not found
  • Loading branch information
akinross committed Nov 6, 2024
1 parent 5ea9e9a commit 60ddd00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mso/resource_mso_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ func (ndoTemplate *ndoTemplate) getTemplate(errorNotFound bool) error {

cont, err := ndoTemplate.msoClient.GetViaURL(fmt.Sprintf("api/v1/templates/%s", ndoTemplate.id))
if err != nil {

// 404 scenario where the json response is not a valid json and cannot be parsed overwriting the response from mso in the client
if err.Error() == "invalid character 'p' after top-level value" {
return fmt.Errorf("Template ID %s invalid", ndoTemplate.id)
}

// If template is not found, we can remove the id and try to find the template by name
if !errorNotFound && (cont.S("code").String() == "400" && strings.Contains(cont.S("message").String(), fmt.Sprintf("Template ID %s invalid", ndoTemplate.id))) {
ndoTemplate.id = ""
Expand Down
2 changes: 1 addition & 1 deletion mso/resource_mso_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestAccMSOTemplateResourceTenant(t *testing.T) {
ImportState: true,
ImportStateId: "non_existing_template_id",
ImportStateVerify: true,
ExpectError: regexp.MustCompile("invalid character 'p' after top-level value"),
ExpectError: regexp.MustCompile("Template ID non_existing_template_id invalid"),
},
{
PreConfig: func() { fmt.Println("Test: Update the Tenant Template with 1 site") },
Expand Down

0 comments on commit 60ddd00

Please sign in to comment.