From 14014af6c9d8f5690ed5c57a835239f5ad9f212f Mon Sep 17 00:00:00 2001 From: Shreyas Date: Wed, 31 Jul 2024 14:15:13 -0400 Subject: [PATCH] [bugfix] Addition of functionality in client.go to start retry mechanism when Apic returns a status code 404 (#299) --- client/client.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 0b4f0b1..86b13f3 100644 --- a/client/client.go +++ b/client/client.go @@ -554,7 +554,7 @@ func (c *Client) do(req *http.Request, skipLoggingPayload bool) (*container.Cont log.Printf("[DEBUG] HTTP response unique string %s %s %s", req.Method, req.URL.String(), bodyStr) } - if (resp.StatusCode < 500 || resp.StatusCode > 504) && resp.StatusCode != 405 { + if (resp.StatusCode < 500 || resp.StatusCode > 504) && resp.StatusCode != 405 && !isApicNotFound(resp.StatusCode, bodyStr, resp.Header) { obj, err := container.ParseJSON(bodyBytes) if err != nil { log.Printf("[ERROR] Error occured while json parsing: %+v", err) @@ -784,3 +784,11 @@ func (client *Client) PostObjectConfig(objectDn string, objectMap map[string]int return CheckForErrors(respCont, "POST", false) } + +func isApicNotFound(statusCode int, responseBody string, responseHeader http.Header) bool { + serverType := responseHeader.Values("Server") + if statusCode == 404 && strings.Contains(responseBody, "
Cisco APIC
") && len(serverType) == 1 && serverType[0] == "Cisco APIC" { + return true + } + return false +}