Add error message when discovery service returns non 200

status code. Update doc for token.go/Fetch

Signed-off-by: Ankush Agarwal <ankushagarwal11@gmail.com>
This commit is contained in:
Ankush Agarwal 2015-01-25 23:05:53 -08:00
parent 9d5fe6949e
commit b3bcab711e
1 changed files with 6 additions and 1 deletions

View File

@ -36,8 +36,9 @@ func (s *TokenDiscoveryService) Initialize(urltoken string, heartbeat int) error
return nil
}
// FetchNodes returns the node for the discovery service at the specified endpoint
// Fetch returns the list of nodes for the discovery service at the specified endpoint
func (s *TokenDiscoveryService) Fetch() ([]*discovery.Node, error) {
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", s.url, "clusters", s.token))
if err != nil {
return nil, err
@ -52,6 +53,10 @@ func (s *TokenDiscoveryService) Fetch() ([]*discovery.Node, error) {
if err := json.NewDecoder(resp.Body).Decode(&addrs); err != nil {
return nil, err
}
} else {
err = fmt.Errorf("Failed to fetch nodes from Discovery service. "+
"Discovery service returned %d HTTP status code", resp.StatusCode)
return nil, err
}
var nodes []*discovery.Node