Skip to content

Commit

Permalink
Fix up bad merge where error headers got lost (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoe committed May 23, 2022
1 parent b7131b0 commit 14561a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
7 changes: 3 additions & 4 deletions internal/api/rest_client.go
Expand Up @@ -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,
}
}

Expand Down
18 changes: 8 additions & 10 deletions pkg/api/errors.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 14561a4

Please sign in to comment.