A non-successful response returns early

This commit is contained in:
Corey Johnson 2019-10-11 14:23:46 -07:00
parent ddb49557d8
commit 2dc521d589

View file

@ -87,23 +87,25 @@ func graphQL(query string, variables map[string]string, v interface{}) error {
func handleResponse(resp *http.Response, body []byte, v interface{}) error {
success := resp.StatusCode >= 200 && resp.StatusCode < 300
if success {
gr := &graphQLResponse{Data: v}
err := json.Unmarshal(body, &gr)
if err != nil {
return err
}
if len(gr.Errors) > 0 {
errorMessages := gr.Errors[0].Message
for _, e := range gr.Errors[1:] {
errorMessages += ", " + e.Message
}
return fmt.Errorf("graphql error: '%s'", errorMessages)
}
return nil
if !success {
return handleHTTPError(resp, body)
}
return handleHTTPError(resp, body)
gr := &graphQLResponse{Data: v}
err := json.Unmarshal(body, &gr)
if err != nil {
return err
}
if len(gr.Errors) > 0 {
errorMessages := gr.Errors[0].Message
for _, e := range gr.Errors[1:] {
errorMessages += ", " + e.Message
}
return fmt.Errorf("graphql error: '%s'", errorMessages)
}
return nil
}
func handleHTTPError(resp *http.Response, body []byte) error {