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>
This commit is contained in:
parent
68ebfa2f18
commit
c5c977855d
1 changed files with 8 additions and 3 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
@ -208,10 +209,14 @@ func (r *session) searchRepositories(term string, limit int) (*registry.SearchRe
|
|||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
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,
|
||||
})
|
||||
}
|
||||
result := new(registry.SearchResults)
|
||||
return result, errors.Wrap(json.NewDecoder(res.Body).Decode(result), "error decoding registry search results")
|
||||
result := ®istry.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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue