Remove() Now returns the body on non 200 response

This commit is contained in:
Derrick J. Wippler 2019-05-23 15:09:56 -05:00
parent 2ce33c3fea
commit 2e501aa922
2 changed files with 9 additions and 3 deletions

View File

@ -252,7 +252,7 @@ func (g *Group) Remove(ctx Context, key string) error {
return nil, err
}
}
// Remove from our cache first in case we are owner
// Remove from our cache next
g.localRemove(key)
wg := sync.WaitGroup{}
errs := make(chan error)

10
http.go
View File

@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@ -273,9 +274,14 @@ func (h *httpGetter) Remove(ctx Context, in *pb.GetRequest) error {
if err := h.makeRequest(ctx, http.MethodDelete, in, &res); err != nil {
return err
}
res.Body.Close()
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return fmt.Errorf("server returned: %v", res.Status)
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("while reading body response: %v", res.Status)
}
return fmt.Errorf("server returned status %d: %s", res.StatusCode, body)
}
return nil
}