etcdserver: check http StatusCode before unmarshal

Check http StatusCode. Only Unmarshal body if StatusCode is statusOK.
This commit is contained in:
Jingyi Hu
2019-05-07 15:49:02 -07:00
parent f8ad8ae4ad
commit e994a4df01

View File

@@ -395,6 +395,10 @@ func promoteMemberHTTP(ctx context.Context, url string, id uint64, peerRt http.R
return nil, membership.ErrIDNotFound
}
if resp.StatusCode != http.StatusOK { // all other types of errors
return nil, fmt.Errorf("member promote: unknown error(%s)", string(b))
}
var membs []*membership.Member
if err := json.Unmarshal(b, &membs); err != nil {
return nil, err