diff --git a/provider_client.go b/provider_client.go index 08fd0ca8..bb1a839e 100644 --- a/provider_client.go +++ b/provider_client.go @@ -132,6 +132,12 @@ var applicationJSON = "application/json" // Request performs an HTTP request using the ProviderClient's current HTTPClient. An authentication // header will automatically be provided. func (client *ProviderClient) Request(method, url string, options RequestOpts) (*http.Response, error) { + return client.request(method, url, options, false) +} + +// Request performs an HTTP request using the ProviderClient's current HTTPClient. An authentication +// header will automatically be provided. +func (client *ProviderClient) request(method, url string, options RequestOpts, recursionFlag bool) (*http.Response, error) { var body io.ReadSeeker var contentType *string @@ -187,7 +193,7 @@ func (client *ProviderClient) Request(method, url string, options RequestOpts) ( // Set connection parameter to close the connection immediately when we've got the response req.Close = true - + // Issue the request. resp, err := client.HTTPClient.Do(req) if err != nil { @@ -195,6 +201,9 @@ func (client *ProviderClient) Request(method, url string, options RequestOpts) ( } if resp.StatusCode == http.StatusUnauthorized { + if recursionFlag { + return nil, fmt.Errorf("Successfully re-authenticated, but got error executing request: %s", err) + } if client.ReauthFunc != nil { err = client.ReauthFunc() if err != nil { @@ -204,7 +213,7 @@ func (client *ProviderClient) Request(method, url string, options RequestOpts) ( options.RawBody.Seek(0, 0) } resp.Body.Close() - resp, err = client.Request(method, url, options) + resp, err = client.request(method, url, options, true) if err != nil { return nil, fmt.Errorf("Successfully re-authenticated, but got error executing request: %s", err) }