Ver código fonte

registry: session.searchRepositories(): return typed error, and small cleanup

- return a errdefs.System if we fail to decode the registry's response
- use strconv.Itoa instead of fmt.Sprintf

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 anos atrás
pai
commit
c5c977855d
1 arquivos alterados com 8 adições e 3 exclusões
  1. 8 3
      registry/session.go

+ 8 - 3
registry/session.go

@@ -9,6 +9,7 @@ import (
 	"net/http"
 	"net/http"
 	"net/http/cookiejar"
 	"net/http/cookiejar"
 	"net/url"
 	"net/url"
+	"strconv"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 
 
@@ -208,10 +209,14 @@ func (r *session) searchRepositories(term string, limit int) (*registry.SearchRe
 	defer res.Body.Close()
 	defer res.Body.Close()
 	if res.StatusCode != http.StatusOK {
 	if res.StatusCode != http.StatusOK {
 		return nil, errdefs.Unknown(&jsonmessage.JSONError{
 		return nil, errdefs.Unknown(&jsonmessage.JSONError{
-			Message: fmt.Sprintf("Unexpected status code %d", res.StatusCode),
+			Message: "Unexpected status code " + strconv.Itoa(res.StatusCode),
 			Code:    res.StatusCode,
 			Code:    res.StatusCode,
 		})
 		})
 	}
 	}
-	result := new(registry.SearchResults)
-	return result, errors.Wrap(json.NewDecoder(res.Body).Decode(result), "error decoding registry search results")
+	result := &registry.SearchResults{}
+	err = json.NewDecoder(res.Body).Decode(result)
+	if err != nil {
+		return nil, errdefs.System(errors.Wrap(err, "error decoding registry search results"))
+	}
+	return result, nil
 }
 }