Skip to content

Make empty responses due to 202 Accepted status code more visible. #486

@caarlos0

Description

@caarlos0

I've built a tool to gather all stats of all repos in a given org and rank the users, and, as I just found, some times github returns an empty hash on the endpoint that returns the statistics (client.Repositories.ListContributorsStats on go-github).

I changed github.go to debug the issue:

@@ -415,9 +408,13 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
 		if w, ok := v.(io.Writer); ok {
 			io.Copy(w, resp.Body)
 		} else {
-			err = json.NewDecoder(resp.Body).Decode(v)
+			content, _ := ioutil.ReadAll(response.Body)
+			body2 := ioutil.NopCloser(bytes.NewReader(content))
+			err = json.NewDecoder(body2).Decode(v)
 			if err == io.EOF {
 				err = nil // ignore EOF errors caused by empty response body
+			} else if err != nil {
+				println("Invalid JSON?", string(content))
 			}
 		}
 	}

And, it turns out, github returned an empty hash ({}) on a repo that wasn't changed the last year...

Is there anything doable on the go-github side?

FYI: I'm reporting this issue to the GitHub support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions