From 60ddd001c63727549dd9555f419ed3f30bdf8861 Mon Sep 17 00:00:00 2001 From: akinross Date: Wed, 6 Nov 2024 09:30:58 +0100 Subject: [PATCH] [ignore] Add change to error handling when ndo resturns 404 for template not found --- mso/resource_mso_template.go | 6 ++++++ mso/resource_mso_template_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mso/resource_mso_template.go b/mso/resource_mso_template.go index 30ab91c0..17063fd5 100644 --- a/mso/resource_mso_template.go +++ b/mso/resource_mso_template.go @@ -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 = "" diff --git a/mso/resource_mso_template_test.go b/mso/resource_mso_template_test.go index 006d4d9f..83f1e448 100644 --- a/mso/resource_mso_template_test.go +++ b/mso/resource_mso_template_test.go @@ -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") },