Commit 61a9296b authored by Michelle Noorali's avatar Michelle Noorali

Merge pull request #487 from michelleN/error-handling

ref(client): return cleaner errors
parents cbe756cb af01eeb6
......@@ -83,7 +83,6 @@ func addRepo(c *cli.Context) error {
payload, _ := json.Marshal(repo.Repo{URL: repoURL, Name: name})
msg := ""
if _, err := NewClient(c).Post(chartRepoPath, payload, &msg); err != nil {
//TODO: Return more specific errors to the user
return err
}
format.Info(name + " has been added to your chart repositories!")
......
......@@ -27,6 +27,7 @@ import (
"strings"
"time"
"github.com/kubernetes/helm/pkg/httputil"
"github.com/kubernetes/helm/pkg/version"
)
......@@ -221,8 +222,20 @@ func (r *Response) Success() bool {
// HTTPError creates a new HTTPError from response
func (r *Response) HTTPError() error {
contentType := r.Header.Get("Content-Type")
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
if contentType == "application/json" {
httpErr := httputil.Error{}
json.Unmarshal(body, &httpErr)
return &HTTPError{
StatusCode: r.StatusCode,
Message: httpErr.Msg,
URL: r.Request.URL,
}
} else {
if err != nil {
return err
}
......@@ -231,6 +244,9 @@ func (r *Response) HTTPError() error {
Message: string(body),
URL: r.Request.URL,
}
}
return nil
}
// HTTPError is an error caused by an unexpected HTTP status code.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment