@@ -87,23 +87,25 @@ func graphQL(query string, variables map[string]string, v interface{}) error {
8787func handleResponse (resp * http.Response , body []byte , v interface {}) error {
8888 success := resp .StatusCode >= 200 && resp .StatusCode < 300
8989
90- if success {
91- gr := & graphQLResponse {Data : v }
92- err := json .Unmarshal (body , & gr )
93- if err != nil {
94- return err
95- }
96- if len (gr .Errors ) > 0 {
97- errorMessages := gr .Errors [0 ].Message
98- for _ , e := range gr .Errors [1 :] {
99- errorMessages += ", " + e .Message
100- }
101- return fmt .Errorf ("graphql error: '%s'" , errorMessages )
90+ if ! success {
91+ return handleHTTPError (resp , body )
92+ }
93+
94+ gr := & graphQLResponse {Data : v }
95+ err := json .Unmarshal (body , & gr )
96+ if err != nil {
97+ return err
98+ }
99+
100+ if len (gr .Errors ) > 0 {
101+ errorMessages := gr .Errors [0 ].Message
102+ for _ , e := range gr .Errors [1 :] {
103+ errorMessages += ", " + e .Message
102104 }
103- return nil
105+ return fmt . Errorf ( "graphql error: '%s'" , errorMessages )
104106 }
107+ return nil
105108
106- return handleHTTPError (resp , body )
107109}
108110
109111func handleHTTPError (resp * http.Response , body []byte ) error {
0 commit comments