diff --git a/api/client.go b/api/client.go index b30f5f164..e6ff59c59 100644 --- a/api/client.go +++ b/api/client.go @@ -152,6 +152,8 @@ func (c Client) RESTWithNext(hostname string, method string, p string, body io.R } // HandleHTTPError parses a http.Response into a HTTPError. +// +// The caller is responsible to close the response body stream. func HandleHTTPError(resp *http.Response) error { return handleResponse(ghAPI.HandleHTTPError(resp)) } @@ -196,12 +198,11 @@ func ScopesSuggestion(resp *http.Response) string { // EndpointNeedsScopes adds additional OAuth scopes to an HTTP response as if they were returned from the // server endpoint. This improves HTTP 4xx error messaging for endpoints that don't explicitly list the // OAuth scopes they need. -func EndpointNeedsScopes(resp *http.Response, s string) *http.Response { +func EndpointNeedsScopes(resp *http.Response, s string) { if resp.StatusCode >= 400 && resp.StatusCode < 500 { oldScopes := resp.Header.Get("X-Accepted-Oauth-Scopes") resp.Header.Set("X-Accepted-Oauth-Scopes", fmt.Sprintf("%s, %s", oldScopes, s)) } - return resp } func generateScopesSuggestion(statusCode int, endpointNeedsScopes, tokenHasScopes, hostname string) string { diff --git a/pkg/cmd/gist/create/create.go b/pkg/cmd/gist/create/create.go index 4f51bed25..06b2336b6 100644 --- a/pkg/cmd/gist/create/create.go +++ b/pkg/cmd/gist/create/create.go @@ -286,7 +286,8 @@ func createGist(client *http.Client, hostname, description string, public bool, defer resp.Body.Close() if resp.StatusCode > 299 { - return nil, api.HandleHTTPError(api.EndpointNeedsScopes(resp, "gist")) + api.EndpointNeedsScopes(resp, "gist") + return nil, api.HandleHTTPError(resp) } result := &shared.Gist{} diff --git a/pkg/cmd/repo/delete/http.go b/pkg/cmd/repo/delete/http.go index 659250446..23930e8e0 100644 --- a/pkg/cmd/repo/delete/http.go +++ b/pkg/cmd/repo/delete/http.go @@ -32,7 +32,8 @@ func deleteRepo(client *http.Client, repo ghrepo.Interface) error { defer resp.Body.Close() if resp.StatusCode > 299 { - return api.HandleHTTPError(api.EndpointNeedsScopes(resp, "delete_repo")) + api.EndpointNeedsScopes(resp, "delete_repo") + return api.HandleHTTPError(resp) } return nil