Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Reduce checkResponse code complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaglow committed Dec 26, 2018
1 parent 92433b7 commit bb79e07
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,14 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*htt
// checkResponse checks http response status code and returns an error if
// needed.
func checkResponse(r *http.Response) error {
switch r.StatusCode {
case http.StatusOK:
if r.StatusCode == http.StatusOK {
return nil
default:
var em errorMessage
err := json.NewDecoder(r.Body).Decode(&em)
if err != nil {
return fmt.Errorf(errUnknownFmt, r.Status)
}
return fmt.Errorf(errMessageFmt, r.Status, em.Type, em.Message)
}

var em errorMessage
err := json.NewDecoder(r.Body).Decode(&em)
if err != nil {
return fmt.Errorf(errUnknownFmt, r.Status)
}
return fmt.Errorf(errMessageFmt, r.Status, em.Type, em.Message)
}

0 comments on commit bb79e07

Please sign in to comment.