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

302 Found #98

Closed
phylake opened this issue Apr 10, 2023 · 4 comments
Closed

302 Found #98

phylake opened this issue Apr 10, 2023 · 4 comments

Comments

@phylake
Copy link

phylake commented Apr 10, 2023

I'm hitting this error message

e.Message = fmt.Sprintf("received non 2xx response status %q when fetching %v", resp.Status, req.URL)

where resp.Status is 302 Found

Shouldn't this redirect have been followed?

@bradleyfalzon
Copy link
Owner

Yeah with the default client, it should follow 10 redirects https://pkg.go.dev/net/http#Client, and if this fails should return an error https://cs.opensource.google/go/go/+/refs/tags/go1.20.3:src/net/http/client.go;l=804

Is your client overwriting this behaviour? If there's more than 10 redirects, we should have checked and returned that error.

@phylake
Copy link
Author

phylake commented Apr 11, 2023

No it shouldn't be. I have roughly this

import (
	"net/http"
	"github.com/bradleyfalzon/ghinstallation/v2"
	"github.com/google/go-github/v50/github"
)

const (
	GHEUrl = "https://my-enterprise-endpoint.com"
	ClientId = 1
	InstallationId = 2
	PKPath = "/path/to/app-private-key.pem"
)

func main() {
	transport, _ := ghinstallation.NewKeyFromFile(http.DefaultTransport, ClientId, InstallationId, PKPath)
	transport.BaseURL = GHEUrl

	httpClient := &http.Client{
		Transport: transport,
	}

	ghClient, _ := github.NewEnterpriseClient(GHEUrl, GHEUrl, httpClient)
	
	// ...
}

The default client is just var DefaultClient = &Client{}

@phylake
Copy link
Author

phylake commented Apr 11, 2023

Oh it's a redirect to /login?return_to=...

@phylake
Copy link
Author

phylake commented Apr 11, 2023

I needed to append /api/v3. I didn't because the go-github docs said it would be appended
https://pkg.go.dev/github.com/google/go-github/v50/github#NewEnterpriseClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants