mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-16 01:07:57 +00:00
Return unexpected body as error message.
Unexpected message within body ( without data ) is an indication of error.
This commit is contained in:
@@ -3,6 +3,7 @@ package gql
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@@ -45,13 +46,13 @@ func Query(query string, variables interface{}, headers map[string]interface{})
|
|||||||
req.SetRequestURI(GraphQLUrl)
|
req.SetRequestURI(GraphQLUrl)
|
||||||
res := fasthttp.AcquireResponse()
|
res := fasthttp.AcquireResponse()
|
||||||
if err := fasthttp.Do(req, res); err != nil {
|
if err := fasthttp.Do(req, res); err != nil {
|
||||||
panic("Unable to execute request")
|
return "", err
|
||||||
}
|
}
|
||||||
fasthttp.ReleaseRequest(req)
|
fasthttp.ReleaseRequest(req)
|
||||||
body := res.Body()
|
body := res.Body()
|
||||||
toReturn := gjson.Get(string(body), "data")
|
toReturn := gjson.Get(string(body), "data")
|
||||||
if toReturn.String() == "" {
|
if toReturn.String() == "" {
|
||||||
fmt.Println("Probably not what you expect:", string(body))
|
err = errors.New(string(body))
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
fasthttp.ReleaseResponse(res)
|
fasthttp.ReleaseResponse(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user