machinebox / graphql

Simple low-level GraphQL HTTP client for Go
https://blog.machinebox.io/a-graphql-client-library-for-go-5bffd0455878
Apache License 2.0
933 stars 217 forks source link

HTTP rate limit errors are not propagated. #72

Open smettu1 opened 2 years ago

smettu1 commented 2 years ago

Github graphql errors.

We were running a lot of graphql queries using multiple coroutines, we were running into issues where data returned is null. In this case, we assume there is no more data from Github and stop the iteration. Eventually, we realized that data that we have doesn't match up with that of Github. Further debugging we found that we were getting secondary rate limit errors which were not sent back to the client.

Function: c.runWithJSON(ctx, req, resp)

    res, err := c.httpClient.Do(r)
    if err != nil {
        return err
    }
    defer res.Body.Close()

Does not propagate 403 rate limit errors , in which case if there is 403 library will try to read the data and pass it upstream. Example error message:

"documentation_url": "https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#secondary-rate-limits",
  "message": "You have exceeded a secondary rate limit. Please wait a few minutes before you try again."

Sample fix:

if res.StatusCode != 200 {
return errors.Wrap(err, "status code error ")
}