diff --git a/introspection.go b/introspection.go index 91e6f70..63b2161 100644 --- a/introspection.go +++ b/introspection.go @@ -73,7 +73,7 @@ func IntrospectAPI(queryer Queryer) (*ast.Schema, error) { } // if we dont have a name on the response - if remoteSchema.QueryType.Name == "" { + if remoteSchema == nil || remoteSchema.QueryType.Name == "" { return nil, errors.New("Could not find the root query") } diff --git a/queryer.go b/queryer.go index 755d3c9..3d3587a 100755 --- a/queryer.go +++ b/queryer.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "net/http" "reflect" + "strconv" "github.com/vektah/gqlparser/v2/ast" ) @@ -164,6 +165,11 @@ func (q *NetworkQueryer) sendRequest(acc *http.Request) ([]byte, error) { } defer resp.Body.Close() + // check for HTTP errors + if resp.StatusCode < 200 || resp.StatusCode > 299 { + return body, errors.New("response was not successful with status code: " + strconv.Itoa(resp.StatusCode)) + } + // we're done return body, err }