Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up bad merge where error headers got lost #43

Merged
merged 1 commit into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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