Skip to content

RepositoriesService.DownloadContents should handle response codes #1531

@mctofu

Description

@mctofu

To download the contents of a file the DownloadContents method is using a http.Client to request it and then returns only the body of the response.

			resp, err := s.client.client.Get(*contents.DownloadURL)
			if err != nil {
				return nil, err
			}
			return resp.Body, nil

The http.Client docs state that A non-2xx response doesn't cause an error. If the download request returns a failed response code then resp.Body most likely doesn't contain the content you wanted and there is no way to tell that something went wrong.

I'd suggest using github.CheckResponse on the response or perhaps a simpler 2XX check since raw.githubusercontent.com may have different behavior than the api.

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