A non-successful response returns early
This commit is contained in:
parent
ddb49557d8
commit
2dc521d589
1 changed files with 17 additions and 15 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue