internal/getproviders: Add URL to error message for clarity (#30810)

* internal/getproviders: Add URL to error message for clarity

Occasionally `terraform init` on some providers may return the following error message:

Error while installing citrix/citrixadc v1.13.0: could not query provider
registry for registry.terraform.io/citrix/citrixadc: failed to retrieve
authentication checksums for provider: 403 Forbidden

The 403 is most often returned from GitHub (rather than Registry API)
and this change makes it more obvious.

* Use Host instead of full URL
This commit is contained in:
Radek Simko 2022-04-14 16:14:50 +01:00 committed by GitHub
parent 696bd4c794
commit 746af015ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -437,7 +437,7 @@ func (c *registryClient) getFile(url *url.URL) ([]byte, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%s", resp.Status)
return nil, fmt.Errorf("%s returned from %s", resp.Status, resp.Request.Host)
}
data, err := ioutil.ReadAll(resp.Body)
@ -478,7 +478,7 @@ func maxRetryErrorHandler(resp *http.Response, err error, numTries int) (*http.R
// both response and error.
var errMsg string
if resp != nil {
errMsg = fmt.Sprintf(": %s returned from %s", resp.Status, resp.Request.URL)
errMsg = fmt.Sprintf(": %s returned from %s", resp.Status, resp.Request.Host)
} else if err != nil {
errMsg = fmt.Sprintf(": %s", err)
}