Skip to content

Commit

Permalink
🐛 Close #502 / Fix roundtrip error handling (#508)
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx authored Jun 23, 2020
1 parent fa7307e commit 61fed82
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/net/http/transport/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/vdaas/vald/internal/backoff"
"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/log"
)

type ert struct {
Expand Down Expand Up @@ -65,9 +66,16 @@ func (e *ert) roundTrip(req *http.Request) (res *http.Response, err error) {
if err == nil {
return res, nil
}
if res != nil {
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
if res == nil {
return nil, err
}
_, err = io.Copy(ioutil.Discard, res.Body)
if err != nil {
log.Error(err)
}
err = res.Body.Close()
if err != nil {
log.Error(err)
}
switch res.StatusCode {
case http.StatusTooManyRequests,
Expand Down

0 comments on commit 61fed82

Please sign in to comment.