Skip to content

Commit

Permalink
Handle error on response.Body.Close()
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Oct 5, 2020
1 parent 05e314e commit e145c3b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions accounts/pkg/storage/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ func (r CS3Repo) LoadAccount(ctx context.Context, id string, a *proto.Account) (
return &notFoundErr{"account", id}
}

defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
var b []byte
if err = dec.Decode(&b); err != nil {
return err
}
if err = resp.Body.Close(); err != nil {
return err
}
return json.Unmarshal(b, &a)
}

Expand Down Expand Up @@ -165,12 +167,14 @@ func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err
return &notFoundErr{"group", id}
}

defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
var b []byte
if err = dec.Decode(&b); err != nil {
return err
}
if err = resp.Body.Close(); err != nil {
return err
}
return json.Unmarshal(b, &g)
}

Expand Down

0 comments on commit e145c3b

Please sign in to comment.