diff --git a/binding/client.go b/binding/client.go index 825311236..3fffccbdd 100644 --- a/binding/client.go +++ b/binding/client.go @@ -681,13 +681,14 @@ func (r *Client) send(rb func() (*http.Request, error)) (response *http.Response err = liberr.Wrap(err) return } - } else if r.refreshToken(response.StatusCode) { + } else if r.refreshToken(response.StatusCode, request.URL.Path) { unAuthErr := errors.New("401 Unauthorized") if i < r.Retry { + Log.Info("|401| Unauthorized, refreshing auth token.") token := api.Login{Refresh: r.token.Refresh} - refreshErr := r.Post(api.AuthRefreshRoot, &token) // calls itself.. ensure no deadlock/stacktoodeep + refreshErr := r.Post(api.AuthRefreshRoot, &token) if refreshErr != nil { - Log.Error(err, "Token refresh failed.") + Log.Error(refreshErr, "Token refresh failed.") time.Sleep(RetryDelay) } else { r.SetToken(token) @@ -816,9 +817,9 @@ func (f *Field) disposition() (d string) { return } -func (r *Client) refreshToken(status int) (refresh bool) { - if status == 401 && r.token.Refresh != "" { +func (r *Client) refreshToken(status int, path string) (refresh bool) { + if status == 401 && !strings.HasSuffix(path, api.AuthRefreshRoot) && r.token.Refresh != "" { refresh = true } return -} \ No newline at end of file +} diff --git a/binding/richclient.go b/binding/richclient.go index dc6bc697f..a560c3003 100644 --- a/binding/richclient.go +++ b/binding/richclient.go @@ -1,8 +1,6 @@ package binding import ( - "time" - "github.com/jortel/go-utils/logr" "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/settings" diff --git a/test/api/client/client.go b/test/api/client/client.go index a69d6e1a0..c8b21d8a9 100644 --- a/test/api/client/client.go +++ b/test/api/client/client.go @@ -27,8 +27,8 @@ func PrepareRichClient() (richClient *binding.RichClient) { panic(fmt.Sprintf("Cannot login to API: %v.", err.Error())) } - // Disable HTTP requests retry for network-related errors to fail quickly. - richClient.Client.Retry = 1 + // Disable HTTP requests retry for network-related errors to fail quickly. + richClient.Client.Retry = 1 return } \ No newline at end of file