You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found this while working on the terraform kong plugin. In getService(), it doesn't check for the 500 error return by kong. When that happens, a nil object is returned, which incorrectly represents the state of the object. For example, if it's 40x, it returns an error which leads one to think 5xx should also be exposed to the client.
I fixed the code as follows but I didn't submit a PR due to two reasons.
This is everywhere in the code and I fixed it in one place.
I'm not sure my crude way of fixing it by using retries follows the intent of the original developer.
So I put the code here.
func (serviceClient *ServiceClient) getService(endpoint string) (*Service, error) {
for count := 0; count < 5; count++ {
r, body, errs := newGet(serviceClient.config, endpoint).End()
if errs != nil {
return nil, fmt.Errorf("could not get the service, error: %v", errs)
}
if r.StatusCode == 401 || r.StatusCode == 403 { // Return immediately if it's unauthorized
return nil, fmt.Errorf("not authorised, message from kong: %s", body)
}
if r.StatusCode == 404 {
return nil, nil
}
if r.StatusCode == http.StatusOK { // Return immediately if it's OK.
service := &Service{}
err := json.Unmarshal([]byte(body), service)
if err != nil {
return nil, fmt.Errorf("could not parse service get response, error: %v", err)
}
if service.Id == nil {
return nil, nil
}
return service, nil
}
}
return nil, fmt.Errorf("Unable to retrieve service after 5 retries")
}
The text was updated successfully, but these errors were encountered:
I found this while working on the terraform kong plugin. In getService(), it doesn't check for the 500 error return by kong. When that happens, a nil object is returned, which incorrectly represents the state of the object. For example, if it's 40x, it returns an error which leads one to think 5xx should also be exposed to the client.
I fixed the code as follows but I didn't submit a PR due to two reasons.
So I put the code here.
The text was updated successfully, but these errors were encountered: