Skip to content

Commit

Permalink
if response is 400, check json for errorMessages and log them
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuff committed Feb 19, 2015
1 parent dc5ae42 commit 4924dfa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions jira/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,19 @@ func runTemplate(templateContent string, data interface{}, out io.Writer) error
func responseToJson(resp *http.Response, err error) (interface{}, error) {
if err != nil {
return nil, err
} else {
return jsonDecode(resp.Body), nil
}

data := jsonDecode(resp.Body)
if resp.StatusCode == 400 {
if val, ok := data.(map[string]interface{})["errorMessages"]; ok {
for _,errMsg := range val.([]interface{}) {
log.Error("%s", errMsg)
}
}
}


return data, nil
}

func jsonDecode(io io.Reader) interface{} {
Expand Down

0 comments on commit 4924dfa

Please sign in to comment.