From 9046a3667148cd7d90fcfe5b5129cdb81a348c79 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Mon, 23 May 2022 16:12:25 +0200 Subject: [PATCH] Fix up bad merge where error headers got lost --- internal/api/rest_client.go | 7 +++---- pkg/api/errors.go | 18 ++++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/internal/api/rest_client.go b/internal/api/rest_client.go index f1651e2..19d1607 100644 --- a/internal/api/rest_client.go +++ b/internal/api/rest_client.go @@ -38,10 +38,9 @@ func (c restClient) Request(method string, path string, body io.Reader) (*http.R success := resp.StatusCode >= 200 && resp.StatusCode < 300 if !success { err = api.HTTPError{ - StatusCode: resp.StatusCode, - RequestURL: resp.Request.URL, - AcceptedOAuthScopes: resp.Header.Get("X-Accepted-Oauth-Scopes"), - OAuthScopes: resp.Header.Get("X-Oauth-Scopes"), + Headers: resp.Header, + RequestURL: resp.Request.URL, + StatusCode: resp.StatusCode, } } diff --git a/pkg/api/errors.go b/pkg/api/errors.go index 7f92fb9..950ce5d 100644 --- a/pkg/api/errors.go +++ b/pkg/api/errors.go @@ -18,12 +18,11 @@ var jsonTypeRE = regexp.MustCompile(`[/+]json($|;)`) // HTTPError represents an error response from the GitHub API. type HTTPError struct { - AcceptedOAuthScopes string - Errors []HTTPErrorItem - Message string - OAuthScopes string - RequestURL *url.URL - StatusCode int + Errors []HTTPErrorItem + Headers http.Header + Message string + RequestURL *url.URL + StatusCode int } // HTTPErrorItem stores additional information about an error response @@ -103,10 +102,9 @@ func matchPath(p, expect string) bool { // HandleHTTPError parses a http.Response into a HTTPError. func HandleHTTPError(resp *http.Response) error { httpError := HTTPError{ - StatusCode: resp.StatusCode, - RequestURL: resp.Request.URL, - AcceptedOAuthScopes: resp.Header.Get("X-Accepted-Oauth-Scopes"), - OAuthScopes: resp.Header.Get("X-Oauth-Scopes"), + Headers: resp.Header, + RequestURL: resp.Request.URL, + StatusCode: resp.StatusCode, } if !jsonTypeRE.MatchString(resp.Header.Get(contentType)) {