Skip to content

Commit

Permalink
[bugfix] Addition of functionality in client.go to start retry mechan…
Browse files Browse the repository at this point in the history
…ism when Apic returns a status code 404 (#299)
  • Loading branch information
shrsr authored Jul 31, 2024
1 parent 391eafe commit 14014af
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, "<hr><center>Cisco APIC</center>") && len(serverType) == 1 && serverType[0] == "Cisco APIC" {
return true
}
return false
}

0 comments on commit 14014af

Please sign in to comment.