Skip to content

Commit

Permalink
closing the response body for service_key operations and service_inst…
Browse files Browse the repository at this point in the history
…ance operations (#256)

Co-authored-by: Gosavi, Rajendra Jayendra <rajendra.gosavi@ge.com>
  • Loading branch information
rajendragosavi and Gosavi, Rajendra Jayendra committed Oct 30, 2020
1 parent 4cf7741 commit e8dadde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion service_instances.go
Expand Up @@ -73,6 +73,7 @@ func (c *Client) ListServiceInstancesByQuery(query url.Values) ([]ServiceInstanc
if err != nil {
return nil, errors.Wrap(err, "Error requesting service instances")
}
defer resp.Body.Close()
resBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(err, "Error reading service instances request:")
Expand Down Expand Up @@ -123,7 +124,7 @@ func (c *Client) GetServiceInstanceByGuid(guid string) (ServiceInstance, error)
if err != nil {
return ServiceInstance{}, errors.Wrap(err, "Error requesting service instance")
}

defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
return ServiceInstance{}, errors.Wrap(err, "Error reading service instance response")
Expand Down Expand Up @@ -167,6 +168,7 @@ func (c *Client) CreateServiceInstance(req ServiceInstanceRequest) (ServiceInsta
return ServiceInstance{}, errors.Wrapf(err, "Error creating service, response code: %d", res.StatusCode)
}

defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
return ServiceInstance{}, errors.Wrap(err, "Error reading service instance response")
Expand All @@ -186,6 +188,7 @@ func (c *Client) UpdateServiceInstance(serviceInstanceGuid string, updatedConfig
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted {
return errors.Wrapf(err, "Error updating service instance %s, response code %d", serviceInstanceGuid, resp.StatusCode)
}
Expand All @@ -197,6 +200,7 @@ func (c *Client) DeleteServiceInstance(guid string, recursive, async bool) error
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted {
return errors.Wrapf(err, "Error deleting service instance %s, response code %d", guid, resp.StatusCode)
}
Expand Down
4 changes: 3 additions & 1 deletion service_keys.go
Expand Up @@ -52,6 +52,7 @@ func (c *Client) ListServiceKeysByQuery(query url.Values) ([]ServiceKey, error)
if err != nil {
return nil, errors.Wrap(err, "Error requesting service keys")
}
defer resp.Body.Close()
resBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(err, "Error reading service keys request:")
Expand Down Expand Up @@ -144,7 +145,7 @@ func (c *Client) CreateServiceKey(csr CreateServiceKeyRequest) (ServiceKey, erro
if resp.StatusCode != http.StatusCreated {
return ServiceKey{}, fmt.Errorf("CF API returned with status code %d", resp.StatusCode)
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
Expand All @@ -164,6 +165,7 @@ func (c *Client) DeleteServiceKey(guid string) error {
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
return errors.Wrapf(err, "Error deleting service instance key %s, response code %d", guid, resp.StatusCode)
}
Expand Down

0 comments on commit e8dadde

Please sign in to comment.