Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Jan 19, 2018
2 parents 413e380 + cbef7f6 commit 05df806
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,12 +946,20 @@ type Error struct {
}

func newError(resp *http.Response) *Error {
type ErrMsg struct {
Message string `json:"message"`
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return &Error{Status: resp.StatusCode, Message: fmt.Sprintf("cannot read body, err: %v", err)}
}
return &Error{Status: resp.StatusCode, Message: string(data)}
var emsg ErrMsg
err = json.Unmarshal(data, &emsg)
if err != nil {
return &Error{Status: resp.StatusCode, Message: string(data)}
}
return &Error{Status: resp.StatusCode, Message: emsg.Message}
}

func (e *Error) Error() string {
Expand Down

0 comments on commit 05df806

Please sign in to comment.